Welcome to Synthiam!

Program robots using technologies created from industry experts. EZ-Builder is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.
Get Started

Portugal
Asked — Edited

Please Help With Script

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)

#1  
Assuming you are using the EZ-Builder script language it should be like this:

Code:


:servo_left
If ($RR_NV_TURRET_LEFT = 1)
Move( D12, "left" ) #Note the quotes
EndIf
#The Goto(servo_right) line is not needed

# :servo_right ... This line also not needed
If ($RR_NV_TURRET_RIGHT = 1)
Move( D12, "right" )
EndIf

Goto(servo_left)

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:


:servo_move
If ($RR_NV_TURRET_LEFT = 1)
Move( D12, "left" ) #Note the quotes
ElseIf ($RR_NV_TURRET_RIGHT = 1)
Move( D12, "right" )
EndIf
Sleep(500)
Goto(servo_move)
#2  
Is your turret a 360 continuous rotation (modified) servo? If not, move is not the correct command. Servo() os the rifht command, and you would need to specify the position you want it to go to. If it is a 360 servo, your script is never telling it to stop moving. Now, that could be intentional if you are setting the variable in another place. Move() assumes the 360 servo is mounted horizontally so forward and back are the correct commands, not left/right. You'll just need to determine what direction is forward and which is back and adjust your script accordingly.

Alan
Portugal
#3  
Thanks guys, that was very helpful. This is the code now and it works great!:

: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...
;)
#4  
@proteusy

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 ($RR_NV_TURRET_LEFT = 1)
servo(D12,0)
Elseif ($RR_NV_TURRET_RIGHT = 1)
servo(D12,180)
Else
servo(D12,90)
endif

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.