
proteusy
Hi, i am trying to move a servo left or right from a variable coming from Roborealm
but i get this error:
2: If ($RR_NV_TURRET_LEFT = 1) then Move( D12, left )
> Error on line 2: Missing String Quotes or Invalid Expression: then Move( D
------------------------------------------------------------------------------------------------------------------
This is what i coded:
:servo_left
If ($RR_NV_TURRET_LEFT = 1) then Move( D12, left )
EndIf
Goto(servo_right)
:servo_right
If ($RR_NV_TURRET_RIGHT = 1) then Move( D12, right )
EndIf
Goto(servo_left)
Code:
Though I'm not sure left and right are valid to use with the "Move" instruction. The manual says Move (servoPort, forward/stop/reverse). Indicating that the valid words to use with Move are "forward" "stop" "reverse"
EDIT Forgot to mention there are other things needed such as sleep statements or Setting the variables to a standby state at the end. Otherwise the loop will operate way too often.
Also, depending on what else you may want to do with the basic code, you could condense it to:
Code:
Alan
:servo_move
ServoSpeed( D12, 5 )
if ($RR_NV_TURRET_LEFT = 1)
servo(D12,0)
Elseif ($RR_NV_TURRET_RIGHT = 1)
servo(D12,180)
endif
Sleep(500)
if ($RR_NV_TURRET_LEFT = 0) and ($RR_NV_TURRET_RIGHT = 0)
servo(D12,90)
endif
Goto(servo_move)
Now comes the HBridge Movement part...
Just a small point. The line:
if ($RR_NV_TURRET_LEFT = 0) and ($RR_NV_TURRET_RIGHT = 0)
is not really necessary.
This is the state if neither variable is 1, therefore can be taken care of in the same If-ElseIf statement like this:
Code:
If both variables are 0, then neither will be taken care of by the first two If and ElseIf statements so the logic will go to the final Else statement and do what it says. The Else statement is a catch-all that takes care of whatever the statements above it do not handle.
Keep in mind, however, it doesn't always work out this neatly so using the Else statement is not always the proper course of action.