I am currently a high school senior enrolled in PLTW Principals of engineering class. My group and I are working on an alternate activity in which we had to design a robot to accomplish a specific task, that robot must use Mecanum wheels. I am currently having trouble with writing code to run the robot correctly. I have gotten the code to run both sets of wheels forward and backward, a conveyor to run forward and backward, as well as raising the arm of the robot up and down. The problems is when I try in include code to run the robot side to side or to turn the robot, the motors become jerky and the robot no longer runs properly or at all.
task main()
{
while(1 == 1)
{
motor[frontRightMotor] = vexRT[Ch2];
motor[backRightMotor] = vexRT[Ch3];
motor[frontLeftMotor] = vexRT[Ch2];
motor[backLeftMotor] = vexRT[Ch3];
if(vexRT[Btn8U] == 1)
{
motor[leftarmmotor] = 127;
motor[rightarmmotor] = -127;
}
else if(vexRT[Btn8D] == 1)
{
motor[leftarmmotor] = -40;
motor[rightarmmotor] = 40;
}
else;
{
motor[leftarmmotor] = 0;
motor[rightarmmotor] = 0;
}
if(vexRT[Btn8L] == 1)
{
motor[rightconmotor] = 65;
motor[leftconmotor] = -65;
}
else if(vexRT[Btn8R] == 1)
{
motor[rightconmotor] = -65;
motor[leftconmotor] = 65;
}
else;
{
motor[rightconmotor] = 0;
motor[leftconmotor] = 0;
}
}
}
This is my current code and I am trying to include 2 more groups of codes, one to run the back wheels in opposite directions to turn (one set for each direction left and right), and another to set all wheels moving so that the robot moves side to side (right or left).
Hi and welcome to the forum,
The problem you are describing sounds like you are popping your drivetrain motor’s internal breakers.
When you apply load to a DC motor (like the 393 motor) it generates heat - the more load the more heat. An overloaded motor will overheat and die. VEX 393 motors include a breaker that will trip to protect the motor from overheating. If you trip the breaker, it will reset a few seconds after throttle is no longer applied. The breaker trips when it becomes hot, so if it trips once it will trip very easily until it has time to sit and cool. The motor should return to full performance after the breaker has had time to cool (15-20mins).
You can reduce the load on each motor by adding additional motors to your drivetrain or gearing it slower. What gearing are you currently using? Do your motors have the “high speed” or “high torque” internal gear set installed? (The motors come with the “high torque” internal gears installed)
Sorry you are having this issue, please let me know if this helps,
Charles
The 393 motors that we are using right now are geared for torque, as well as we have another external gear system for each wheel increasing the amount of torque. Our robot does have a large amount of weight and this setup did help for the speed of the robot. But with the code that I have now the robot runs completely fine. but once I add any more code the motors on the whole robot malfunction. can you see any error in my current code that would cause a malfunction or misinterpretation of the code, once I add say a, " if (vexRT[Btn6U] ==1)
{
motor[backLeftMotor] = -127;
motor[backRightMotor] = 127;
}
else if(vexRT[Btn6D] == 1)
{
motor[backLeftMotor] = 127;
motor[backRightMotor] = -127;
}
else
{
motor[backLeftMotor] = 0;
motor[backRightMotor] = 0;
}
"
else;
{
motor[rightconmotor] = 0;
motor[leftconmotor] = 0;
}
This is the cause of the motor jitter; when you put a semicolon after an if, else, or while loop’s condition or keyword, you are essentially ‘ending’ the code controlled by the if, else, or while loop. Since the very next thing in your code is two commands to turn the motors off, the code is actually reading as:
if(one button is pressed)
{
Do something with the motors
}
else if(a different button is pressed)
{
do something different with the motors
}
else; <----The else statement will do absolutely nothing (it won't even turn the motors off. This also ends the if/else if/else block
vvv This code will be run no matter what button is pressed or not pressed
{
motor[leftarmmotor] = 0;
motor[rightarmmotor] = 0;
}
Or, an easier way to look at this:
if(one button is pressed)
{
Do something with the motors
}
else if(a different button is pressed)
{
do something different with the motors
}
motor[leftarmmotor] = 0;
motor[rightarmmotor] = 0;
What is essentially happening in this case is that the motors are turned on with a button press, then immediately turned back off. This will cause the motors to ‘jitter’ as they rapidly switch between on/off states. Try removing the semicolons from your else statements and running the program again, and it should work properly.
Thanks this did help alot!