How do I program 2 motor in ROBOTC Graphical

I am new to RobotC and am having good luck so far. I am trying to write an autonomous program, but I have hit a block. I have a lift that has 2 motors that are opposite of each other. In the autonomous I must have them move at the same time and not sequentially. How would I have them move at the same time?

I suppose you tried using moveMotor() and realized that if you use moveMotor for one and then moveMotor for the second, the second one will only start moving once the first one finished.
That’s because moveMotor is a blocking function - it gets the motor moving, but it will wait until it finishes before moving onto next line of your program.

What you can use instead are similar non-blocking functions: setMotorTarget/moveMotorTarget. If you’re using graphical, you’d first need to claim you’re an expert: Go to the “Window” menu, select “Menu Level” and then “Expert”. If you feel short-changed, don’t worry and go straight for the “Super User”.

After that, you’ll have extra Motor (and other) commands available in the Graphical Functions catalog.

How does setMotorTarget/moveMotorTarget work? Each motor is basically a servo. It knows its position and also knows where you want it to go. That is the “target”. You can reset the internal counter by calling resetMotorEncoder() for given motor, that will set current motor position as 0 (zero). If you call setMotorTarget(100), the function will return immediately, but the motor will start working towards getting to the position 100, as that is it’s new target. The motor (based on proper “brake mode”) would then try to maintain that position - if you force-turn it (don’t try hard, you could break it), it would try to return back to position 100. setMotorTarget values are absolute, based on the last reset, thus if you call setMotorTarget(100) twice in a row, the motor would just keep position of 100.
The difference with moveMotorTarget is that it is relative to current target (not current position, which could be different if the motor is still moving toward the target). So if you call moveMotorTarget(100) twice in a row, it would actually aim at 200.

I’ll let you figure the actual program for moving two motors yourself.

Good luck!

1 Like

To move to 2 motors issue two commands. See example Here it uses both motor10 and motor11.

Just wanted to ask whether this solution worked? We’re facing the same issues. Any alternative solutions?

Using setMotorTarget/moveMotorTarget works well for both autonomous and teleop. As these functions are not blocking, you might want to add waitUntil(getMotorMoving(oneOfTheMotors)==0) after both motor commands. You can easily try this with just two motors and a brain, no mechanics around needed for the test.

As for the suggestion to use armControl() twice, that works (reasonably) well for teleop, but is unusable for autonomous.

True, armControl() was an example to show how to use two motors in graphical version of a thread already there… There are examples in the sample programs already.

Please help!!!
I am using RobotC Grafphical. I still trying to move 2 arm(lift) Motor at the same time but could not figure out how to do. Is there a example code so I can look at it and apply to my robot? Thanks

Here’s a good resource to learn the basics of RobotC Graphical:

As to your question of moving two motors at the same time, here is one way to do it (there are usually many different ways to accomplish the same solution):

  1. Turn on all the motors that need to move using “setMotor” commands. Unlike the “movemotor” commands, which execute a motor start, condition, and stop, setMotor just starts the motor and the program continues.

  2. “waitUntil” something happens. Usually you use a timer or a sensor value

  3. “stopMultipleMotors” to turn off the motors you started in step 1.

Here’s a snip of typical code, borrowed from the trainer I linked to above.


This doesn’t use the position PID like the other example using moveMotorTarget.

We are having the same trouble and do not completely understand the above. Could you snapshot a picture of an example ??
It would so help my team!!

If you are using both motors on the same shaft (one on each end), you can reverse one of them in the “Motor and Sensors Setup”.

Then you can use SetMultipleMotors to command both at the same time.

SetMultipleMotors(armLeft, armRight, none, none, 50)

You will have to decide how long or far they will move in a later statement. depending on your needs.