PLEASE HELP!! Need help programming arm??

Now I am an electronics guy not a coder, but I can still do some programming if needed. Our programmer is lazy and never gets things done, so I was wondering if you guys had some ideas of how we could use an encoder (connected to a cim motor to control our arm) to give our arm a smooth and controllable movement. How can we control the speed of the motor based on encoder feedback.
We are planning to use the Y-axis of the joystick to control the direction of the arm.
We are using the Banebots encoders, and are ready to use the divider kits if necessary.

Some example code would be appreciated, because then I could understand the solution better.
Please leave any comments or questions that you have.
Thanks in advance to all the helpers.

P.S to moderators, I made a similar post on a different thread, but I thought my question might get answered much quicker if I started a new thread. (So I have no means of spamming). Thanks

If you were to search CD Media (papers) for “PID” - which is “Proportional, Integral and Differential” controls, you’ll find several very good resources, including example code. For a very brief description, please look here:

In CD Media Papers “PID”

BTW, it is NOT GP to slam a team member (or anyone, for that matter) in CD. You should consider apologizing, even though you are probably frustrated.

What are you attempting to do? Do you want the joystick to control the position of the arm, or do you simply want the joystick to control the speed of the arm movement?

If you want the joystick to control the position of the arm, you’ll need a PID loop and a way of calculating where the arm is using the encoder. You’ll also have to ensure(Unless its an absolute encoder) that the arm starts at the same position every time.

If you want to control the speed, then you’ll still need a PID loop

Feel free to talk to me on aim (evil666rat), I’ll be happy to help - I’m the programmer who wrote the code controlling our arm. I’ll be happy to build some for yours, if you’ll contact me with some more details.

The way you code will depend on how the arm works. You need to do things a bit differently if the arm will hold position by itself, or if you need to
continuously apply power to keep it in position.

Early in our season, we had a prototype robot with a pivoting arm and we found that using a pot on an analog input was an easy way to detect the position without the mess of servicing an encoder.

You can still use a PID routine to adjust your speed and maintain a position once you have achieved it.

With an arm that does not hold position by itself, we found we were popping the breakers a lot. We used a big bungee to counteract the force of gravity (so the motor’s didn’t need to work so hard to maintain a lifted position).

Our PID looked at a target POT value to move the arm to and adjusted the power to the arm motor based on the distance. When we wanted the arm to stay in a position that we had moved it to with the joy stick, we look at the current POT value and set the target value to it. This resulted in an arm that could be pushed or pulled out of position, but which would return to where you wanted it when it was released.

Good luck.

You guys are suggesting PID?!?! :eek:

K.I.S.S. 237’s arm works off a P loop with a “gain” of 1. If it needed to be more complex it would be, but we found that theres more or less no overshoot or oscillation with this system.

First lets make sure the path of least resistance is closed (open, if you want to use electrical terms :p) before we suggest complex closed loop control theory.

Team Voltage uses a PD loop with differentiating “goals” depending on what position you want the arm to be in.

–Chris
Lead Programmer

Thanks for replying guys,
Can someone explain the PID loop in depth, and show an example or something that can help me get started.

Just some more information about the arm.
It will have an encoder, since the encoder gives back feed back can’t that be just used to keep the arm at a preset constant speed??

Or is this something that PID has taken into consideration.
The help has been great so far, please keep it coming.

Read this paper.

Since this is your first PID loop, I would recommend not using “I” if you can avoid it. “I” can really help if the system is perfectly tuned; but it is difficult to get it that way. A PD loop is more forgiving, although it can be slower.

Are there any downsides of using a PID loop and what success have you guys had using a PID loop on you robots???

Downsides… Hmm… they do take work to tune…

success: Arms that would have been nearly impossible to manually control are quickly and precisely control. Another feature you get almost for free is the ability to go to “preset” positions - the arm position to pickup, score high, etc… - quickly and accurately.

If you get the control on there, I don’t think you’ll regret it.

I am going to have to agree with Mike on this one, PID (or even PD) is a bit much, especially since he said he wasn’t a programmer. Now before you tell me how much better off you are with PID think about how long it takes for you to tune your loops, now realize that he doesn’t have the robot, probably until competition. There is almost no chance that he will be able to get the robot to himself for long enough to get every thing working, especially with it being his first try.

I would reccomend using a pot instead of an encoder, they are much easier to work with.

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

Amir:
You understand that the encoder generates pulses as the arm moves, whereas a pot will provide an analog voltage that corresponds to the position of the arm? If you use the encoder, the software will need to update the position of the arm as pulses are detected. With a pot, each time you read the analog port it is connected to, you get instantaneous position data. This is why teams generally use pots on arms rather than encoders.