Programming Motors for Arm

I am a rookie programmer this year. Our team is using motors on each arm joint to control the arm position. How do I set it up so that a joystick axis or a joystick button can control a motor? Also, I want to have several “presets” for the arm position so that it will minimize the amount of work our driver has to do. How can I set it up so that, for example, button 1 will align the arm with the top middle peg. I just need to set up something that will say "when button 1 is pressed: run both window motors in their correct directions x degrees and run the second joints motor y degrees at the same time.

Our arm setup is: one arm coming up from chassis, bolted to chassis; at the top of that there is a joint that is controlled by 2 window motors facing opposite directions(that is they need to be run at the same time, one clockwise, one counterclockwise to work the joint); then that arm joint proceeds about 2 feet out and there is another joint there that is run by only 1 motor. then the arm ends in the claw.

Thank You for All Help in Advance, and I prefer pictures but anything will work as long as it explains clearly.

Uh this is a bit complex because of the number of motors but Ill try.
The two things that I need to know are what is controlling the motors (if at all possible use speed controllers (we use victors so I don’t know the can system on jags if you need can). Also do you have encoders/potentiometers attached (the only way this will be possible)?

(will only work with speed controllers) Now to have set positions (you will need 6) what I did is to have a toggle between middle and outside columns and then 3 buttons to designate which row. Then make a case statement decided by a Boolean array with what values you want (it will come out in binary into the case). now wire a PID (wiki it its kinda complicated) VI outside of the case with your encoder values going to the process variable and some numerical value inside going to the setpoint. Then the output to a motor set vi. You will need to do this 3 separate times i think. (I know im forgetting something but Ill post a pic of my 2 motor system code for you to look at)

If you just want a manual control with speed controllers (which since your new to this is suggested). You just wire whatever axis you want to control the motors to the input on the motor set.

If you need further help I’m willing to post pictures. I guarantee I left something important out.





I am going to be using Jaguars to control the arm motors. And by encoders do you mean I need to attach the US digital encoders to the motor axles?

If so, how do I wire these?(I’ll look at the sensor manual but I’m hopeless with technical diagrams)

Is there not a way to have a case structure that holds a set motor vi and I can set the motor to run EITHER at x speed for y seconds OR for x degrees??
It seems to me that this would be quite a bit easier.

I’m going to look over your code tonight and try to make sense of what everything does. I’ll probably be able to post tomorrow to ask questions and clarify some stuff. Thank You!

Yes you could use a timer to run the motor for X number of seconds. It’s a quick and easy way of doing some preset height work.

You will need some kind of sensor to get position feedback. You could use the US digital encoders, but that may not be the easiest way. I recommend using a potentiometer for any joint that does not rotate more than 360 degrees. There are also absolute position magnetic encoders that you could use if you want the joint angle but the arm rotates more than 360 degrees. There is information for wiring all of these in their data sheets. For a pot you are going to connect one side to power, the other to ground, and the wiper to signal. If you can’t figure out how to wire the sensors I recommend asking a mentor. It is better for him to teach you how to read a data sheet than it is for us to tell you how to wire a specific component.

You can do this but it will not work well. As battery voltage changes the distance travelled in that time will vary greatly. Also errors will compound, if you travel too far in one direction, then not far enough while returning then try to travel back in the original direction and go too far again you could be off by a significant amount. Repeat for an entire match and you could have the motors trying to overrun the physical capabilities of the joints.

In general you don’t want to use timers. It is not difficult to add a potentiometer to a joint and the benefits of having closed loop control on your arm far outweigh the effort.

Ok, In your experience what are the best potentiometers for this kind of use?

And then I just need to set the code to run motor A until the potentiometer gives me angle x? Also, are potentiometers accessed via the generic DIO vi on LabView? And then how is this coded? I will write some code today at the shop to try and get this done and I will post it tonight if I can.

Just be warned: Its bound to have quite a few errors in it. All I learned how to do last year(from our less-than-great-teacher programmer) was how to set up mecanums and how to wire solenoids.

And does the potentiometer read degrees? So can I just do the thing from paragraph 2 up above?
Or will I have to do something else?

You can go to radio shack and pick up your choice of potentiometers, make sure they have a linear taper, and look at 10k pots.

Potentiometers are conected to the analog inputs on the controller. If you just turn on the motor until you get to the desired angle you will overshoot it every time, and not by a predictable amount. You should look into PID control.

Ok…what on earth does the PID control actually do?

And I set up some quick code on a blank VI that I think will do what I want it to do which is basically take 1/4th the speed of the joystick and set the motors to run at that speed. This is for fine-tuning of the arm position if we have the presets working. The image is attached.

And when I wire the potentiometer is the signal wire supposed to go to the analog card on the ccRIO>





Looking up the wiring diagrams for everything is just going to put you in circles.

For Pots you wire 3 cables (pwm cable) into an analog port on the cRIO, one to the power one to the ground and one to the wiper (the wiper is your signal).

For encoders you wire The voltage, a signal, and ground to one female pwm end and the b signal and ground to another pwm. Both of these pwm’s go into the dsidecar

LabView wise for pots you read the driver station analog input (1-4) reference example “Potentiometer with Driver Station”. If you want the degrees you will have to do some math which involves your potentiometer size (10K or whatever it is) and the voltage given from the analog input port on the cRIO (i think its 5v not sure though).

For encoders you need to open 2 DIO’s in the begin (dsidecar ports) and put them into a couple encoder vi’s (in the WPI library) which I don’t know the whole row so follow the “Encoder Example” example to know for sure.

PID is a mildly complex control system (wiki it thats how I learned it a few weeks ago actually) that will slow down the motor output until it hits the correct values (or goes over in which case it will reverse).

Fun stuff and yet again with such a big post I probably forgot something.

It’s a way for software to ‘gracefully’ bring some quantity to a specific value.

OK, some examples: You are riding a bicycle. You want to stop right at a fire hydrant by the curb. You wouldn’t go at full speed, and then slam on the brakes at the right moment - too much chance for missing the spot. Instead you slow down gradually, stopping exactly where you want. This is PID control, the quantity being the exact spot where you will stop.

Another example: A Cruise control in a car. You set the system to maintain a certain speed, and it does. A good system does not apply full throttle when the speed drops one or 2 MPH because of a hill, it applies a little throttle, only adding more if the hill is too steep to maintain the ‘set’ speed. This is PID control, the quantity being the set speed.

PID stands for Proportional, Integral, Derivative. Proportional means that you apply a corrective signal (like a car’s throttle) in proportion to the difference (“error”) between the actual value and the desired value. A car going 2 MPH slower than the set speed needs only a little throttle, but one going 30 MPH too slow needs a lot of throttle.

Integral helps keep a steady value when the P “error” is very small. It adds up the error over time, so that even a small error gets compensated for after several seconds.

Derivative keeps you from making changes too rapidly, but allows you to make big changes when necessary. You don’t want the cruise control at full throttle until 1 MPH below the setpoint - you’ll “overshoot” the set speed and have to slow down. Instead this works with P do gradually hit the set speed.

In robotics, PID can be used to move an arm to a set position. Depending on the mechanism, P may be enough, or possibly PI. Full PID is often overkill and unnecessary in a typical FRC design.

There are two schools of thought to this, but personally I prefer PID control because I have seen/done it before effectively. If you want pre set positions, I would say that the potentiometer + PID to be the best control system for your robot. Not only will the values stay consistant, the arm will almost always go into the same position (assuming that you don’t move the potentiometer (or pot)). The PID function is found under the analog tab. Basically, the set point determines what voltage the pot should read at the desired position, the process variable is the raw instantanious pot reading, the array of 3 values that are used to tune the loop (bottom always 0, mid is 0 or really small, top is the tuning number >0). The top output is the value you set your motors to. It is a bit confusing, pm me if you need examples/extra explination.

How will I determine the correct voltage when I get the arm position I want? And then for the process variable, which I understand to be the actual position of the pot, you mentioned an array; is this preset in the PID or will I have to do something extra for that?

You physically position the arm where you want it, then measure the pot output in LabVIEW (front panel indicator or probe), or you use a multi-meter to get your voltage reading.

Here’s a quick .vi I wrote to learn about PIDs. It’s not perfect but it allows you to simulate what a motor using a PID would look like. I think I did a decent job labeling everything, if not feel free to PM me and I’ll explain anything you need.

I’ve already uploaded this in a different thread, here’s the link. http://www.chiefdelphi.com/forums/showthread.php?t=90604

Another option is to first convert your potentiometer voltage to an angle (The relationship should be of the form angle=m*voltage + offset). You can then use that angle to calculate the height of your arm end effector (you’ll likely need to draw out the geometry to arrive at the correct equation). Your presets could then be set in inches from the floor.

What should I set the top to? Can it be any number I want? And if so what would be the difference between, for example, 2 and 3?

And one of the posts said the top value is the one you set your motor to, so I figured this was just the motor output. However, one of the pics of code had a box with 1 on top and -1 on the bottom and the actual motor set leading from the left edge of the PID. Which is the correct way for our robot?

The PID block has quite a few terminals which you want to wire specific things to.

I’ll start at the top and rotate around the VI counterclockwise.

On the top you want to wire a constant to the Output Range terminal by right clicking and selecting “Create->Constant”. For most FRC applications you want to change the default 100 and -100 to 1 and -1.

Setpoint is where you wire the point you want to device to go to.
Process Variable is where you wire the measurement of the device’s position.
You must make sure that the Setpoint and Process Variable have the same units, the PID block will try to drive the Process Variable until it matches the Setpoint.

For tuning purposes you likely want to make a control for the PID gains terminal. A good starting place for the tuning of a position loop is to set the Integral Time and Derivative Time to 0.

To find a starting point for the Proportional Gain, estimate the smallest error you want to still result in the maximum output. Then take the max output (usually 1) and divide by the error and you will have a starting point for the P gain. I would actually start the tuning with a gain lower than this number. I highly recommend reading this paper to understand the basic concepts so you can tune your PID loop.

One thing to be careful of is the Labview implementation of PID is different than the implementation described in the paper. Labview uses Integral Time(Ti) and Derivative Time(Td) instead of Integral Gain(Ki) and Derivative Gain(Kd). The conversion is Kp equals Kc, Ki equals Kc/Ti, and Kd equals KcTd.

The output terminal of the PID block should be wired into the Motor Set Speed VI.