Code question

I have created some code for ym vex reverse 4bar and have got some code making it turn forward and backwards when I clicka button but I need help with creating code so when I release the button it stops the arm

I believe it would be something like this:

if(!button.pressed()) {
     Arm.stop()
}
1 Like

SOrry, I ment in blocks

Screen Shot 2021-01-15 at 5.11.24 PM

This is the code that I have so far, I would like to be able to stop ti when I release E. (Don’t mind the forever block I just did that by accident)

is there a block for the if statement for not pressed? And also a stop block?

Happy cake day @seismic_sans201x!!!

3 Likes

image

This is an option. You need to nest some if/else statements. The logic goes something like this:

If E up is pressed, spin the motor forwards
Else if E down is pressed, spin the motors the other way
Else (i.e. neither E Up nor E Down are pressed), stop the motors

2 Likes

theres a braketype called hold.
it powers the motor but it isnt “stopping” the motor it holds it while you arent pressing the button.
if you just tell the motor to stop itll just stop giving the motor power to move
telling it to hold will tell the brain to give the motor enough power to keep the motor position in place rather than cutting the power to it

1 Like

This is important. Set your brake type to hold but also try to band your arm in a way that takes strain off the motors as they may get warm if constantly holding.

2 Likes

that is the one downside to hold
if its holding something effected by gravity for a long period of time
the motors will over heat and will loose a lot of their efficiency
i havent found a way around this through programming but maybe something mechanical like a one way shelf that the arms can sit on
then its just a matter of pulling the shelfs up to go back down

If you rubber band the arm well this should not be a problem. You should have enough tension that the bands essentially hold the arm up on their own, and the motors are just there to facilitate changes in height. This takes a huge amount of stress off the motors and they should not overheat on hold.
One way to rubberband a DR4B

1 Like

Yeah I did that too but I didnt have enough time before the comp to do extensive testing on it so the motors were doing about 65%-70% of the work rather than the rubber bands

Screen Shot 2021-01-15 at 5.11.24 PM
When I use drive control on my arm, it works perfectly fine but when I use this code m arm breaks for some reason.

Please refer to my post further up.
The code you posted will only make the arm go in one direction forever and never stop.
Use the nested structure that I recommended and make sure it is all inside the forever loop.


oops, wrong screenshot

Nearly. Put your holds up the top with your torque etc as these are just config blocks. In the last else, you need the motor stop blocks instead.

1 Like

Thanks soo much, it works a lot better now

1 Like