@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.
Asked
— Edited
Code:
and loop them while the joystick button is pressed and set a max value for that specific servo to stop at.
Code:
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
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?
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.
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.
Code:
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.
@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....
Code:
and the command script...
Code:
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.
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.
Code:
is incorrect syntax
The correct syntax is
Code:
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.
Alan
That's just one method that could work, I'm sure there are other methods, probably even better methods.
Thank you, thank you, and again thank you.
Thanks again.
Added to my project list.
Alan
@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.
Code:
and
Code:
and then in the joystick control when the button is pressed down run
Code:
and then for when the button is released you run
Code:
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
Thanks for your response. I appreciate it. I'm golden now.