|
Re: PLEASE HELP!! Need help programming arm??
I am going to repeat what others have said in this thread...
Using a potentiometer on the arm axis instead of an encoder on the motor will make your task a LOT easier. You can read the pot directly through an RC analog input, but the encoder takes a lot more work to accurately count pulses when the motor is moving...
You can get very good positioning using simple "P", proportional control, which amounts to taking the difference between the position where you want the arm to be, and where it is, and sending that to the arm motor PWM output. Something similar to this would work:
int ArmPosition;
int ArmPostionSetpoint;
int ArmMotorOutput;
// Read the arm position and scale so zero is at a known position,
// like when the arm is horizontal.
ArmPosition = GetAnalogInput(xxx) - 250; // replace 250 with your actual value
// Scale this number down to match the range of the joystick.
ArmPosition /= 4;
// Read the arm joystick and scale so that zero is the normal resting position.
ArmPositionSetpoint = p2_y - 127;
// Take the difference between setpoint and position, and apply a gain factor.
ArmMotorOutput = (ArmPositionSetpoint - ArmPosition) * 4;
// limit the value of ArmMotorOutput to an acceptable range for your drive.
if (ArmMotorOutput > 80) ArmMotorOutput = 80;
if (ArmMotorOutput < -80) ArmMotorOutput = -80;
PWMxx = (char)(ArmMotorOutput + 127 );
This isn't perfect, but it should get you started...
Jim
Last edited by JimGRobot : 15-03-2007 at 16:00.
|