I am new to coding so be gentle.
I am having trouble with the mogo lift. I am using a 4 bar with 2 motors with a 1:7 gear ratio for torque. Without a load, the lift works fine. When a load is introduced, it seems to work once, if I am lucky, and then does not work.
I have been told that I may not be getting enough power to the motors with the PID control. Any help with this would be greatly appreciated.
I am posting my code here:
if(vexRT[Btn5U]) {
pidGoal = SensorValue[frontMogoLeft] + 900;
}
else if(vexRT[Btn5D]) {
pidGoal = SensorValue[frontMogoLeft] - 900;
//else
//pidGoal = 0;
}
Here is the PID task file titled mogoPid.c:
static float pidKp = 0.35;
static float pidGoal;
float pidGoalR;
/-----------------------------------------------------------------------------/
/* pid control task /
/-----------------------------------------------------------------------------*/
task pidMogoL()
{
float pidSensorCurrentValue;
float pidError;
float pidDrive;
while( true )
{
// Read the sensor value and scale
pidSensorCurrentValue = SensorValue[frontMogoLeft];
// calculate error
pidError = pidGoal - pidSensorCurrentValue;
// calculate drive
pidDrive = (pidKp * pidError);
// limit drive
if( pidDrive > 127 )
pidDrive = 127;
if( pidDrive < (-127) )
pidDrive = (-127);
// send to motor
motor[frnMogoLeft] = pidDrive;
pidGoalR = pidGoal + 52;
// Don't hog cpu
wait1Msec( 25 );
}
}
task pidMogoR()
{
float pidSensorCurrentValue;
float pidError;
float pidDrive;
while( true )
{
// Read the sensor value and scale
pidSensorCurrentValue = SensorValue[frontMogoRight];
// calculate error
pidError = pidGoalR - pidSensorCurrentValue;
// calculate drive
pidDrive = (pidKp * pidError);
// limit drive
if( pidDrive > 127 )
pidDrive = 127;
if( pidDrive < (-127) )
pidDrive = (-127);
// send to motor
motor[frnMogoRt] = pidDrive;
// Don't hog cpu
wait1Msec( 25 );
}
}
I know I have probably done something incredibly stupid and made a very simple oversight of something very basic but with no coding experience, I really am lost. Any help would be greatly appreciate.
I am confident the mechanics are sound so I must be doing something wrong in my code.