code issue

6 years 4 months ago #29529078 by Beginner
code issue was created by Beginner
BatteryVolts = getvalue(_V, 2)

accel = setcommand(_GO, 1, 500) 

if accel = 500
	setcommand(_GO, 1, 0)
else
	setcommand(_GO, 1, 500)
end if

Courant = getvalue(_A, 1)

print ("Batterie = ",BatteryVolts," Courant = ",Courant,"\r")

wait(100)

I can't run my code because there is a error for line 2 : "No Function named 'setcommand' that takes '3' arguments"

If I delete "accel", I can compile and run my code.

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529079 by Griffin Baker
Replied by Griffin Baker on topic code issue
accel = setcommand(_GO, 1, 500) is the problem. Setcommand is its' own function.

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529080 by Beginner
Replied by Beginner on topic code issue
I want to set Motor 1 at 500. When Motor 1 is 500 for a few milliseconds, immediately I set Motor 1 at 0.

Do you have something else idea for about it ?

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529081 by Griffin Baker
Replied by Griffin Baker on topic code issue
Simply remove the accel = part. The motor 1 is set to go +500 at the start of script.


BatteryVolts = getvalue(_V, 2)

setcommand(_GO, 1, 500)

if accel = 500
setcommand(_GO, 1, 0)
else
setcommand(_GO, 1, 500)
end if

Courant = getvalue(_A, 1)

print ("Batterie = ",BatteryVolts," Courant = ",Courant,"\r")

wait(100)

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529085 by Beginner
Replied by Beginner on topic code issue
I can run this code but it doesn't work as I want.

The motor 1 is set to go +500 at the start of script. When motor 1 is 500 for a few microsecond (I use a function "wait (50/100)"), immediately I want to stop the script or set Motor at 0.

I don't know what to do.

Could you hep me, please !

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529086 by Griffin Baker
Replied by Griffin Baker on topic code issue
From what you have here it is looking at accel. But you don't actually define a value for it. Earlier you defined it as a setcommand for the motor to be +500 which is invalid.

A few microseconds is too short. What exactly do you plan to achieve in the few microseconds?

If you give us a better idea of what it is you are trying to do, then writing the code to do what it is that you are trying to do would become easier.

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529087 by Griffin Baker
Replied by Griffin Baker on topic code issue
Based on your previous code since no other directions were given. This is also not tested.

dim Time as integer
dim MotorState as integer
Time = 500 ' 500mS
MotorState = 0

Top:

if MotorState = 0 and gettimerstate(1) = 1
setcommand(_G, 1, 500)
else
setcommand(_GO, 1, 0)
end if
MotorState = 1
if motor state = 1 then terminate
goto top

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529094 by Beginner
Replied by Beginner on topic code issue
My frequency PWM = 20 kHz => My period = 50 µs.

I want to generate a signal with only one period. Therefore I plan to achieve in the few microseconds.

With a duty cycle = 50 % (setcommand(_GO, 1, 500)), my signal is ON for 25 µs. After 25 µs, it is OFF and script will be stopped.

But my code generates a signal periodic : it is ON for 25 µs, it is OFF for 25 µs and it is ON again for 25 µs...

Please Log in or Create an account to join the conversation.

6 years 4 months ago #29529097 by Griffin Baker
Replied by Griffin Baker on topic code issue
Then send the stop command follow by a "terminate" as that will end the script.

If you are using my script, then modify and remove the goto statement as it causes the script to loop over and over.

Please Log in or Create an account to join the conversation.

6 years 3 months ago #29529105 by Beginner
Replied by Beginner on topic code issue

Griffin Baker wrote: Based on your previous code since no other directions were given. This is also not tested.

dim Time as integer
dim MotorState as integer
Time = 500 ' 500mS
MotorState = 0

Top:

if MotorState = 0 and gettimerstate(1) = 1
setcommand(_G, 1, 500)
else
setcommand(_GO, 1, 0)
end if
MotorState = 1
if motor state = 1 then terminate
goto top


You declare a variable "Time" but you don't use it in main function ?

Please Log in or Create an account to join the conversation.

Time to create page: 0.153 seconds