#pragma config(Sensor, in1, Arm_Pot, sensorPotentiometer)
#pragma config(Sensor, dgtl1, Lower_Limit, sensorTouch)
#pragma config(Motor, port1, A_L, tmotorNormal, openLoop)
#pragma config(Motor, port2, D_L_R, tmotorNormal, openLoop)
#pragma config(Motor, port3, D_L_RE, tmotorNormal, openLoop)
#pragma config(Motor, port4, D_L_HS, tmotorNormal, openLoop)
#pragma config(Motor, port5, C_L, tmotorNormal, openLoop)
#pragma config(Motor, port6, C_R, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port7, D_R_HS, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port8, D_R_RE, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port9, D_R_R, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port10, A_R, tmotorNormal, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include “Vex_Competition_Includes.c” //Main competition background code…do not modify!
const int HIGH_GOAL = 1700;
const int MEDIUM_GOAL = 1200;
const int LOW_GOAL = 900;
const int GROUND = 270;
float ARM_POWER;
float ARM_TARGET;
int MAX_HEIGHT = 1700;
int MIN_HEIGHT = 270;
int ARM_ERROR_CAP = (MAX_HEIGHT - MIN_HEIGHT) / 2;
int ARM_INTEGRAL_CAP = 15000;
int ARM_LAST_TARGET = 0;
float ARM_ERROR = 0;
float ARM_INTEGRAL = 0;
float ARM_LAST_ERROR = 0;
float ARM_DERIVATIVE = 0;
float ARM_KP = ((MAX_HEIGHT - MIN_HEIGHT) / 2) / 127;
float ARM_KI = 4;
float ARM_KD = 0.25;
const int cycle = 25;
//D denotes Drive
//L denotes Left
//R denotes Right
//P denotes Power
//C denotes Constant
//V denotes Value
void pre_auton()
{
}
task autonomous()
{
}
void Assign_Motor(int L, int R)
{
motor[D_L_R] = L;
motor[D_L_RE] = L;
motor[D_L_HS] = L;
motor[D_R_HS] = R;
motor[D_R_RE] = R;
motor[D_R_R] = R;
}
float Ramp(float Last_V, int Current_V)
{
float Dummy;
if (abs(Current_V - Last_V) < Cycle)
Dummy = Current_V;
else
if ((Current_V - Last_V) > 0)
Dummy += Cycle;
else
Dummy -= Cycle;
return Dummy;
}
float Ramp_T(float Last_V, int Current_V)
{
float Dummy;
if (abs(Current_V - Last_V) < Cycle)
Dummy = Current_V;
else
if ((Current_V - Last_V) > 0)
Dummy += Cycle;
else
Dummy -= Cycle;
return Dummy;
}
task Drive()
{
float D_Last_L_P = 0;
float D_Last_R_P = 0;
float D_L_P = 0;
float D_R_P = 0;
int J_L_V = 0;
int J_R_V = 0;
while (true)
{
ClearTimer(T1);
J_L_V = vexRT[Ch3];
J_R_V = vexRT[Ch2];
if (abs(J_L_V) < 15)
D_L_P = 0;
else
D_L_P = Ramp(D_Last_L_P, J_L_V);
if (abs(J_R_V) < 15)
D_R_P = 0;
else
D_R_P = Ramp_T(D_Last_R_P, J_R_V);
Assign_Motor(D_L_P, D_R_P);
D_Last_L_P = D_L_P;
D_Last_R_P = D_R_P;
while (time1[T1] < 13)
{
}
}
}
task Arm()
{
while (true)
{
ClearTimer(T2);
if (vexRT[Btn7DXmtr2] || vexRT[Btn7D])
ARM_TARGET = GROUND;
if (vexRT[Btn7UXmtr2] || vexRT[Btn7U])
ARM_TARGET = LOW_GOAL;
if (vexRT[Btn8DXmtr2] || vexRT[Btn8D])
ARM_TARGET = MEDIUM_GOAL;
if (vexRT[Btn8UXmtr2] || vexRT[Btn8U])
ARM_TARGET = HIGH_GOAL;
if (vexRT[Btn5U])
{
motor[A_L] = 127;
motor[A_R] = 127;
}
else
{
if (vexRT[Btn5D])
{
motor[A_L] = -127;
motor[A_R] = -127;
}
else
{
if (ARM_TARGET == GROUND)
{
if (SensorValue(Lower_Limit) != 1)
{
motor[A_L] = -127;
motor[A_R] = -127;
}
else
{
motor{A_L] = -10;
motor[A_R] = -10;
}
}
else
{
if (abs(ARM_TARGET - SensorValue(Arm_Pot)) > 0)
{
if (abs(ARM_POWER) < 10)
{
motor[A_L] = 0;
motor[A_R] = 0;
}
else
{
if (ARM_POWER < 0)
{
motor[A_L] = ARM_POWER;
motor[A_R] = ARM_POWER;
}
else
{
motor[A_L] = ARM_POWER;
motor[A_R] = ARM_POWER;
}
}
}
else
{
motor[A_L] = 0;
motor[A_R] = 0;
}
}
}
}
if (ARM_TARGET < MAX_HEIGHT)
if (vexRT[Btn5UXmtr2])
ARM_TARGET+=10;
if (ARM_TARGET > MIN_HEIGHT)
if (vexRT[Btn5DXmtr2])
ARM_TARGET-=10;
if (vexRT[Btn6U] || vexRT[Btn6UXmtr2])
{
motor[C_L] = 127;
motor[C_R] = 127;
}
else
{
if (vexRT[Btn6D] || vexRT[Btn6DXmtr2])
{
motor[C_L] = -127;
motor[C_R] = -127;
}
else
{
if (vexRT[Btn8L] || vexRT[Btn8LXmtr2])
{
motor[C_L] = 127;
motor[C_R] = -127;
}
else
{
if (vexRT[Btn8R] || vexRT[Btn8RXmtr2])
{
motor[C_L] = -127;
motor[C_R] = 127;
}
else
{
motor[C_L] = 0;
motor[C_R] = 0;
}
}
}
}
ARM_ERROR = ARM_TARGET - SensorValue(Arm_Pot);
if (ARM_ERROR > ARM_ERROR_CAP)
ARM_ERROR = ARM_ERROR_CAP;
else
if (ARM_ERROR < -ARM_ERROR_CAP)
ARM_ERROR = -ARM_ERROR_CAP;
if (ARM_TARGET != ARM_LAST_TARGET)
ARM_INTEGRAL = 0;
if ((ARM_INTEGRAL > ARM_INTEGRAL_CAP) || (ARM_INTEGRAL < -ARM_INTEGRAL_CAP))
if (ARM_INTEGRAL < 0)
ARM_INTEGRAL = -ARM_INTEGRAL_CAP;
else
ARM_INTEGRAL = ARM_INTEGRAL_CAP;
ARM_INTEGRAL = ARM_INTEGRAL + ARM_ERROR / 100;
ARM_DERIVATIVE = ARM_ERROR - ARM_LAST_ERROR;
if (ARM_ERROR > 0)
ARM_POWER = ARM_ERROR / ARM_KP + ARM_INTEGRAL / ARM_KI;// - ARM_DERIVATIVE / ARM_KD;
else
ARM_POWER = (ARM_ERROR / ARM_KP + ARM_INTEGRAL / ARM_KI) * 0.75;
if (abs(ARM_POWER) > 127)
if (ARM_POWER > 0)
ARM_POWER = 127;
else
ARM_POWER = -127;
while (time1[T2] < 13)
{
}
ARM_LAST_ERROR = ARM_ERROR;
ARM_LAST_TARGET = ARM_TARGET;
}
}
task usercontrol()
{
// User control code here, inside the loop
StartTask(Drive);
StartTask(Arm);
while (true)
{
if (vexRT[Btn7L])
{
StopTask(Arm);
wait1Msec(250);
StartTask(Arm);
}
}
}
Here’s the code.
I’ve tried tweaking a lot of things such as how often the loops goes through (currently it’s at 13 ms) / Stopping the task / Moving all the code into the main task (to take out the possibility of multi-tasking interfering with… whatever).
I have not tried to send the motors a power of 0 (removing it away from PID). I’ll try that to see if it makes any difference. I didn’t put it as one of the first things to try because it didn’t seem like the motors are overheating (it didn’t heat up at all plus in my encounters the motors took longer to reset). Do motors “wear out” and drop in performance significantly?
The motors stop working whenever. It seems random to me however it doesn’t occur nearly often when I used a USB connection between the joystick and the cortex, if that’s an indication for anything. Oh and also, whenever the connection is back on after disconnecting, the motors seem to be running full power without any trouble. I’m not quite sure about the thermal fuse but doesn’t it take a while to get the motor to full power again?
And yes this is a gateway competition robot. Sorry I didn’t clarify. Gear ratio is 7:1 with an arm that’s roughly 17.5 in. long however one thing that we significantly changed was from a round collector to a “chainsaw” collector. Again we’ve copied the arm from our old robot which ran with the exact same settings and it didn’t have issues for 2 / 3 weeks until now.
No the arm does not stop at the same place all the time. However due to the tubing / gravity it usually rests at wherever the “balance point” is and doesn’t move when it tries to go up and only goes down a little bit. I tested it with the manual override buttons (127 / -127).
Everything else (the drivetrain / collector) works fine when the arm motors stop working.
I’ve not consider the possibility of motor gears breaking but I’ll check tomorrow if all else fails, along with swapping out motors.
I have noticed the motors aren’t moving when the arm stopped moving (the motors are chained (1:1) to the same axle with the 12 tooth gear). I took the chain off and noticed that. I’ll perform the test tomorrow.
I used the debugger window in RobotC to check the motor power and there isn’t any abnormalities that I noticed. The pot is working fine along with bottom limit switch. However I did noticed that (I took the chain off after it stopped working once) the power value sent to the motors are not changing when I manual set it at a certain height. It remains at 127 but when I used the override buttons the motors still has no response.
I downloaded all the newest firmware today and that didn’t make a difference.
Thank you all for your help!