United Kingdom
Asked — Edited

New Script Command Request

@DJ and team.

I give a small request that I hope you would consider adding to EZ-Script.

Would it be possible to add a new script command for servostop()? I'm not talking about the one the one that already exists for modified servos, but for standard ones (more like a stopservo() or possitionstop() command). The idea is to add this for things like controllers and joysticks.

E.g, you have a servo which has a centre possition of 90, and a set max possition of say 160, and a set speed of 2. When a button is pressed on a controller the servo starts to move from 90 towards 160, but if you release the button the servo stops in its current possition and stays there. Press the button again and it continued to travel towards 160, or back to 90 by pressing another button.

I'm aware that there are ways to write a script for this, but I've had a lot of trouble with it so far, and having a simple script command in the script menu would make things so much easier. Would it be something that you would consider adding? And if there is a command to do just this, then I apologise in advance and would appreciate someone informing me of what script command to use.

Thanks, Steve.


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

Trinidad/Tobago
#1  

you can use the functions


ServoUp (servoPort, count)
ServoDown (servoPort, count)

and loop them while the joystick button is pressed and set a max value for that specific servo to stop at.


#set speed of servo
ServoSpeed(D0,2)
if(GetServo(D0)<160)
  ServoUp(D0,2)
  #increases servo position in increments of 2 degrees
endif

#and the reverse being, as a separate script
if(GetServo(D0)>90)
  ServoDown(D0,2)
endif

This could be a simple script that you call each time the button is pressed.

I hope i understood you're problem correctly and that this helps:)

United Kingdom
#2  

@VGosine

Thanks for your reply. I am currently using servoup() and servodown() commands but don't like having to repeatedly press a button to move through increments. I must admit though that I haven't considered using a loop. I will give it a try a little later. Thanks for the advice.:)

I still think having a simple command to use to achieve this would be a good idea. Something that could be put in to "when button is released" in the control config. Is it something you would consider adding DJ? ;)

United Kingdom
#3  

Didn't I provide you with a script which does exactly what you are asking? (Which is pretty much the same method @VGosine posted above).

You shouldn't need to keep pressing a button over and over to make it work. Check out Gwen's B9 movement help topic and the code I provided for her, this runs when button is pressed and stops when released. The project is in my cloud and is public. Use a similar method for your required actions.

United Kingdom
#4  

@Rich.

yeah, the script example you supplied is what I'm currently using which is good, but I do have to keep pressing the button to move each increment I set (I have them set at 10). So if I want the servo to move, to say possition 120, I have to press the button lots of times, and if I change the increment value to 20 or more and want the servo to stop at possition 105, it will over shoot that possition.

I just thought it would be a lot easier to have a specified script command (like servo(), servospeed() ect) to simply stop a servos travel that could be inserted in to the "when button is released" configuration. Kind of like a momentary switch action.

United Kingdom
#5  

Have had a look through Gwens thread and the cloud project. Unfortunately, looking through the code I'm not sure what I'm looking for. Just to be clear, I am talking about joystick/pad "buttons", not the D pad.

#6  

Use some if commands then... set your servo increment to 20... Then use an if statement to set it at 105 if it should over shoot...


If (GetServo(D0) >105
servo(D0,105) #set servo D0 at 105
endif

United Kingdom
#7  

Thanks Richard. I'll try this a bit later. Where do I put this script, in the "when button is pressed" or "when button is released" script editor? (I asume its the first one).

United Kingdom
#8  

If you want everything to stop when the button is released you need that script to be empty and only have the commands, loops and ifs in the on button down part.

While the button is pushed the script will loop.

You may find it easier to write the scripts in script manager and use ControlCommand() with ScriptStart and ScriptStop on the on button down and on button up. This way, when the button is pressed and held the script runs and loops etc. as soon as the button is release the script is stopped by control command.

Check the version history of the project I made for Gwen, originally the movement was assigned to buttons not joysticks as I had a brain fart and totally forgot the joystick controls the movement panel.

#9  

@steve... you mentioned that you need to push the button too many times unless you set the increment to 20... My example code would have to go in the button push script... It checks to see if you pressed the button too many times and have exceeded the 105 ceiling... it then sets the servo to back 105 until you press the down button (or whatever direction you are going)...

@Rich's solution to write separate scripts outside of the button push scripts and to use ControlCommand() to start and stop them is a better method... It keeps code shorter so you don have one massive complicated script that becomes difficult to read and debug....

United Kingdom
#10  

No matter what I try, it's just not doing what I want it to. Here is what I have in the "button 2" config...


IF(GetServo(D19) < 120)
ServoUp(D19, 120)
EndIf
Sleep(100)
ControlCommand("Script", ScriptStart)

and the command script...


if (getservo(D19))>120
servo(D19,120)
endif

All it ends up doing is to travel the set distance even when button 2 is released. I am thankful for your help with this guys, but I just can't figure out what I want to do for this. The closest thing I have have gotten to what I'm asking is to do "servospeed(d19,10)" in "when button is released", which doesn't stop the servo, just slows it down a lot. Having an "11" option that completely stops the servo for example, or a simple script command to accomplish the same thing would be so much easier and removes the need for scripting, just like the other servo script commands that already exist.

United Kingdom
#11  

The command script has invalid syntax on line 1, presumably a typo?

Why does your ServoUp() have a step of 120? That would put the servo in position 120 higher than it is currently in. Why does the ControlCommand() script move the servo to position 120? This would completely go against the point of the small increments.

I've provided you with a script which would work to achieve stepping up or down of a servo. Use it in conjunction with ControlCommand() and ScriptStart and ScriptStop on the button down and button up commands.

United Kingdom
#12  

Sorry, the 120 was a typo. Should have been 20. Don't know what you mean about typo in line 1. If you mean the brackets (), they were needed or the script wouldn't run.

United Kingdom
#13  
if (getservo(D19))>120

is incorrect syntax

The correct syntax is

If (getservo(D19) > 120)
United Kingdom
#14  

Brilliant. Thanks rich. No it wasn't a typo, just my bad coding. I'll try it again a bit later. Had to step away for a while and chill. Getting a lil bit stressed (if you couldn't tell). :P

United Kingdom
#15  

Have a look at this project. In the example it uses the methods which have been explained and advised in this topic.

On pressing button 1 the servo will move in to it's maximum position at 1 degree steps with a 10ms delay between steps. On release it will stop in it's current position. Button 2 does the same but moves the servo down to it's minimum position.

The scripts use a basic loop and an IF surrounding a ServoUp or ServoDown command. Every time the script loops the servo moves one more degree unless the IF condition is not met. The script is triggered with ControlCommand() and ScriptStart. On release of the button the ControlCommand() uses ScriptStop to halt the script from running and therefore stopping the servo in it's current position.

To increase the servo movement speed decrease the sleep or increase the number of degrees. To slow it down increase the sleep time or decrease (if possible) the number of degrees.

#16  

As usual, I am benefiting from the help you are providing others. This is perfect for something I was working on (controlling the claws on my Roli)

Alan

United Kingdom
#17  

Yeah this would work for claws. Tied in with a current monitor on the ADC port you could have it totally autonomous for when closing, when the resistance is high the current increases, this can be picked up by the current monitor, fed in to the ADC, monitored by ARC and can stop the script for closing the claw.

That's just one method that could work, I'm sure there are other methods, probably even better methods.

United Kingdom
#18  

@Rich.

Thank you, thank you, and again thank you. :D That has ended what has been a pretty rubbish day on a real high note. Looking at the code now and it's starting to make sense a lot more now. I obviously still have a long way to go with scripting, but I appreciate all the help (and patience) you and others offer.

Thanks again. :):)

#19  

I was just discussing monitoring how tight the claw was closing using an ADC port. He said the best way would be to open the servo and get resistance from the pot, but that monitoring the ground wire for power spikes would probably also work.

Added to my project list.

Alan

United Kingdom
#20  

@Steve, you're welcome. Hopefully the scripts and explanation make sense and help you understand what's going on:)

@Alan, these work well on the ADC ports, I use a few in my projects. Melvin monitors one for the current to the drive motors so that if he gets stuck it is detected, he also has one for the EZ-B to monitor power being drawn by the EZ-B and connected devices.

They also do an I2C version which looks like it'll work well but I've not used it yet.

Trinidad/Tobago
#21  

@Steve to get the buttons to move the servo when held down and then as it is released the servo stops you can create two scripts:


:loop
if(GetServo(D0)<150)
  ServoUp(D0,1)
endif
sleep(100)
GoTo(loop)

and


:loop
if(GetServo(D0)>75)
  ServoDown(D0,1)
endif
sleep(100)
GoTo(loop)

and then in the joystick control when the button is pressed down run


ControlCommand("Script Manager", ScriptStart, "Move servo Up")
#and
ControlCommand("Script Manager", ScriptStart, "Move servo Down")

and then for when the button is released you run


ControlCommand("Script Manager", ScriptStop, "Move servo Up")
#and
ControlCommand("Script Manager", ScriptStop, "Move servo Down")

So i've tested this method and it seems to work but you may have to adjust the increment you want to increase by as well as the sleep command in the movement scripts

United Kingdom
#22  

@Vgosine.

Thanks for your response. I appreciate it. I'm golden now. :)

Trinidad/Tobago
#23  

Awesome:) I'm glad to help out