Programming a Controller Button Help

I have Elementary School kids that are using RobotC Graphical for their programming and the standard Vex Smart Motors on their bot.

They want to program a controller button to make the robot’s lift arm raise to a certain level, and we just can’t seem to find the right commands to make it work. We managed to make the arm move, but can’t get it to stop at a certain point.

I know it has to start with a “Repeat forever” and then an “if” statement that assigns the task to the button pushed. We can get the bot to move all over the field, but it’s getting the lift arm to raise to a certain spot. Also, they are using a double motor lift arm, so the command has to send power to both motors for a certain amount. Again… we just can’t find it.


“Coach Dave”

@Coach_Dave – you are looking to move the motor a specific number of rotations

See the documents here:

Will this command go for 2 motors simultaneously? Obviously, I would nwed 2 lines of code for it, but if they are n an “if” statement, it should run it… no???

@Coach_Dave Yes, they would be the same command to both motors. Remember to do the reverse flag in the Motor tab. I’m assuming you have a motor on both ends of the shaft.

No expert here, but I’ll take a shot. Please forgive if I assume incorrectly.

You can directly control the arm :
Adjust speed slower maybe, watch they don’t strain motors. And as Foster said, reverse one motor if they face away from each other, also may have to change signs (in power) to ensure up and down is correct. This will get them going.

To hit exact height, a bumpSwitch, the timer, or the motor encoder can be used. Encoder example:

You need to start the program with the arm down. (Or, I have sometimes added a 2 second “down” before the first reset. Don’t want to strain/stall the motors too long, though).

There is some overshoot. Values can be found by trial and error (be ready to turn it off). Or you can show encoder on bot’s LCD using “displayMotorValues” added to the first (direct control) example, and plug those values into the second example. You may need to flip the “greater or equal to” and “less than or equal to”).

Where you get the encoder value:

BrakeMode might help (needs SuperUser menus under “Window>Menu Level” or in RobotC prefs).

This is from memory, I will retest it myself later today.

Also as an aside, the “moveMotorTarget” is relative, so will move from current position when button pressed. You can use that if you reset the encoder each button push (or use math limits on encoder values) to avoid multiple “ups” without a “down”. There is also the danger of an “up” in the middle of a “down” causing overshoot. Also there may be some wandering of set points.

Using “setMotorTarget” is absolute, (though they use the word “relative” confusingly in the help file) and would work. It can be used in the above examples without the “stopMultipleMotors” on the two motors. I have wondered about differences between “setMotorTarget” vs. “setMultipleMotors” plus “stopMultipleMotors” when using encoders.

BTW, bot pics can help, and if you show us code you’ve got so far, that always helps.


How much is an encoder value though? It’s a unit, but nothing that tells me what it’s default is. Degrees? Rotations? ???

Believe it is degrees, 360 for a motor shaft rotation.

I think you replied in another Topic/Thread. By “robot set-up”, you mean the physical bot (show pics) or the Motors and Sensors setup?

To be clear, are they driving using the controller and want the arm to respond to buttons?

Screenshots of graphical code can be uploaded with the 37%20PM icon when editing.

For text code you may have seen to use:
That is, 3 of the upper left key on most keyboards - on a separate line
your code
another 3 on a separate line

it will format as code:

your code

Gonna take a pic of our code. Don’t have the bot for photos. But I can describe it easy enough.