Okay so we are currently using a claw for our robot and we and having troubles with tripping out motors when holding items tightly without claw. I would like to write a P controller for our claw so it automattically doesn’t move when items ar win it. I’ve written a PID controller before but that was the fly wheel last year and that was a constant hold of value. This year I am running the claw and it stops when i release a button so I don’t know how to set the target value using the button to open and close the claw. So if someone could help me with a layout of what I should do for this P controller that would really help.
Wouldn’t it just be easier to apply a braking pressure of 10-15 to hold all the items in? Or am I misunderstanding your issue?
That would help but I would like to use A p controller to now use as much power
Anything much lower than 10 will kind of be useless as far as actually holding in the objects. Do you have a specific reason for wanting to avoid 10 motor power? It has never caused motors to overheat in my experience.
I don’t want our claw to get move and open from stars hitting it when we move aorund the field even when we aren’t holding things
I’ll send you some sample code when I have some more time. Using a P controller is substantially better than just setting a motor power.
Here’s the sample code:
int target = 0; //target value for claw
float kp = 0.5;
float ki = 0.1;
float kd = 0.01;
//these are constants you will need to tune
int derivative = 0;
int integral = 0;
int lastError = 0;
//some variables necessary for PID; you can ignore these two as well as ki/kd if you only want a p controller
void clawPID(){
error = SensorValue[claw] - target;
integral += error;
derivative = error-lastError;
motor[claw] = kp*error + ki*integral + kd*derivative;
lastError = error;
}
task clawControl(){
while(true){
if(vexRT[Btn5U] == 1){
motor[claw] = 127;
target = SensorValue[claw];
} else if(vexRT[Btn6D] == 1){
motor[claw] = -127;
target = SensorValue[claw];
} else {
clawPID();
}
}
}