I have two motors for the arms, the gears combination is different on both arms therefore the gear cartridge has to be different, I want them to move at the same time with one button but I dont know how to program it so that when I press the button both motors move but at different speeds
Great question,
however, we need a little more information about your situation. (Specifically, what language you are programming this in.) The reason I ask this is because there are many key differences in how this would be done in each programming language and you have attached 3 different programming tags to your question.
I was originally doing the blocks but I think the only way to do it is in c++ or python, im familiar with c++ so I would say im trying to do it in c++
OK, In the case of C++ and assuming you are using VEXcode Pro V5 this is what I would do to achieve this:
(Note, there may be better, more efficient ways to do this, but this is just what I have done in the past.
First, you are going to want to put this code in your Driver-Control loop, that is where most of your code for driving goes.
//Somewhere Before and outside of your control loop you need to put these lines:
Motor1.setVelocity(0,percent); Motor1.spin();
Motor2.setVelocity(0,percent); Motor2.spin();
//The folowing code needs to be inside of the control loop.
if (Controller1.ButtonA.pressing()){ //you can change ButtonA to whatever button you need.
Motor1.setVelocity(100,percent); //you may need to adjust the speed to your needs,
Motor2.setVelocity(100,percent); //but this will work with any type of V5 smart motor.
} else {
Motor1.stop()
Motor2.stop()
}
Note that this solution will only work if you want your motors to only spin in one direction, to make it so the motors reverse as well, you need to add an else if statement with the button that reverses the motors, and then, instead of doing…
MotorX.setVelocity(100,percent);
you would do…
MotorX.setVelocity(-100,percent);
Did that answer your question?
Thank you! that answered my question!