Hey everybody, I’ve been mulling over an odd error with my code for my robot arm. The section of my code dealing with automatic movements for the roll joint aren’t working. Essentially, I copied the code from the other joints (which do seem to be working, but use pots instead of an IME), but one of the variables doesn’t seem to want to be “defined”. What is weird is that I define it and am able to use it a number of times without getting an error message (though not working in execution), but when I try to use said variable to update the “error value” of the movement, it gives a “variable undefined, short assumed” compiler error.
In the following code segment, “desiredEncvalue” is used to represent where the joint is trying to get to. It generates no errors up until it is used to redefine the variable for error, at which point, the compiler thinks it hasn’t been defined yet.
task moveRoll()
{
if(robotHomed==true) //roll only moves once the robot is homed.
{
//where the joint is
int currentEncValue = nMotorEncoder(rollMotor);
//where the joint is going
int desiredEncValue = ((targetPosition.rollDeg*rollEncoderConversion)+rollEncoderBaseline);
//if the target is in appropriate range
if((desiredEncValue < 2400)&&(desiredEncValue > -10))
{
if(desiredEncValue > currentEncValue)
{
//then increase enc until equal to target
while(nMotorEncoder(rollMotor)<(desiredEncValue-rollEncoderError))
{
startMotor(rollMotor, 27);
}
stopMotor(rollMotor);
}//if targetEncValue greater than to currentPotValue
else //else if the targetEncValue is less than the currentEncValue
{
while(nMotorEncoder(rollMotor)>(desiredEncValue+rollEncoderError))
{
startMotor(waistMotor, -27);
}//while
stopMotor(waistMotor);
}//else if target less than current
}//if target in range
}//if robot homed
rollEncoderError=desiredEncValue-nMotorEncoder(rollMotor);
rollMoveDone=true;
}//moveRoll
It’s kind of weird. The whole thing boggles my mind. My code for homing the wrist encoder works fine:
void goHome()
{
//moves robot to home position. Wrist and LSB will not move yet since encoders haven't been homed.
//basically, this folds the arm into a good position so it can safely move
//the wrist and LSB without obstruction.
movePos(positionHome);
//runs wrist motor until the reset switch is tripped.
while(SensorValue[rollLimitReset]!=1)
{
startMotor(rollMotor, -27);
}//until the limit switch is tripped
stopMotor(rollMotor);
//reset rollMotorEncoder
nMotorEncoder(rollMotor)=0;
//move wrist to baseline
while(nMotorEncoder(rollMotor)<rollEncoderBaseline-rollEncoderError)
{
startMotor(rollMotor, 27);
}//while encoder is less the baseline corrected for error.
stopMotor(rollMotor);
/*put lsb homing code here*/
//change bool for robotHomed to true to unlock normal movements
robotHomed = true;
}//goHome
Any insights would be appreciated greatly.