We are using the old cortex electronics in my 6th grade robotics class. With v5, we can easily add a hold to the arm motor to have it hold in the position when not being moved up or down.
With the old cortexes, I can’t figure out the command to get it to work.
In short, everything works fine but when I change the last command, everything stops working.
Only the arm commands:
if joystick.b5up():
arm.run(80)
elif joystick.b5down():
arm.run(-80)
else:
arm.off()
That last line I think goes like this:
else:
arm.stop(vex.BrakeType.HOLD)
When I add that line, the entire program fails to move the robot.
Help!
cortex motors did not have that capability
4 Likes
Oh, that explains everything then. My kids are going to be frustrated when they find that out because my example was a v5 robot and it does have that capability.
For an arm you can try blindly commanding something like 15 power. If you have a sensor on the arm you can do something smarter but people have done the “dumb” fixed value to hold the arm.
2 Likes
Cortex motors are much, much simpler than V5 motors. V5 motors can sophisticated electronics, encoders, and voltage regulation inside of them that allow them to put placed into a brake mode and hold their own position. Cortex motors on the other hand do not have these (aside from the optional IME module for an encoder), and are simply just a set of wires directly connected to a motor which spins the output. You can either use PID control to maintain the arm at a particular position (complicated), or you can take the simpler route that many VRC teams of the era did for gravity-affected mechanisms such as arms - just apply a small upward power. For example, for lift arms with 393 motors, I would usually apply a small power of about 8-15 control value (out of [-127,127]) to counteract gravity and that worked fine enough for driver control. You should also consider using rubber bands or other mechanical methods to counteract gravity and give the arm a more neutral buoyancy.
4 Likes
With Cortex you can use Optical Shaft Encoders (or a Potentiometer) to create a hold control.
I had to dig through some old files but I think the following is pretty close.
void max(int value, int maxValue){
return maxValue > value ? maxValue : value;
}
void min(int value, int minValue){
return minValue < value ? minValue : value;
}
int armTarget = 0;
long armPos = 0;
while(true)
{
wait1Msec(10);
if(vexRT[Btn6U]){
//Move Up
motor[leftArm] = motor[rightArm] = 60;
armTarget = SensorValue[armEncoder];
}
else if(vexRT[Btn6D]){
//Move Down
motor[leftArm] = motor[rightArm] = -60;
armTarget = SensorValue[armEncoder];
} else
{
//Hold Position
armPos = SensorValue[armEncoder];
if(abs(armTarget-armPos)> 10)
{
//Apply power to motor to move back to position
motor[leftArm] = motor[rightArm] = max(min(armTarget-armPos, 20),120);
armMoving = true;
}
else
{
motor[leftArm] = motor[rightArm]= 0;
armMoving = false;
}
}
}
3 Likes
Thank you both for great suggestions!
Very well thought out responses that help me immensely. Thank you thank you thank you!