Welcome to Synthiam!

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

Get Started
Asked — Edited
Resolved Resolved by Rich!

Slide Script Help

So Im trying to use use a slide script. I have the variable setup as $RightPWM. If I want to make another script that uses that variable to set the pwm how would I do that? Aka $RightPWM= 5, I want the pwm to change to 5. How would I do this? If statement? Not sure how I would make it.

United Kingdom
#1  

Quote:

PWM(digital port, speed)


Assuming the port is D0 the command would be;

Code:

PWM(D0, $RightPWM)


You will need to make sure $RightPWM is set to something before running the script or command which uses the variable though otherwise it will error as the variable will not exist. I usually add all variables to an init script and set them to 0, this ensures the variables exist and will avoid any scripts failing due to the possibility of an error.
#2  
thanks rich. is there a way to make it so its always one more than the variable?
United Kingdom
#3  
I don't see the point in that, that's the whole idea of a variable but yes.

Code:

PWM(D0,$RightPWM+1)
#4  
Ok thanks. My method is that is if the pwm needs to be 0, and the minimum value for the variable is 1, I guess I could run the pwm one less to successfully stop the motor. Sorry if I'm not making sense lately. Not sure what's gotten into me.
United Kingdom
#5  
Slide Script allows a minimum value of 0 and maximum of 1000 and is configurable. If you set it from 0 to 100 and use the variable for a PWM command it should be exactly the same as adding the PWM control (which therefore makes the whole idea of using the slide script for PWM redundant since you could use the control already available).

What is it you are trying to achieve? There may be a better/different method.
#6  
Its possible im going to run other scripts based of the variable so I just thought id get it sorted out.
United Kingdom
#7  
You could always use the GetPWM() command to run other scripts based on the PWM of the port...

Code:

IF(GetPWM(D0) > 50)


or a WaitForChange() and a GetPWM()

Code:

WaitForChange(GetPWM(D0))


Either way will work, using a slide script or using a PWM control, I always prefer to use the native controls over scripting when possible, they are there to make things easier.