CAN Position control code?

Greetings!

Has anyone modded the CANJaguar.cpp code for position control? Willing to share the code by any chance?

TIA,

Mike

It’s in SVN. http://firstforge.wpi.edu/integration/viewcvs/viewcvs.cgi/?root=canjaguar&system=exsy1002

Hmm… The code in SVN seems to use only the kPercentVoltage control mode.

switch (m_controlMode)
{
case kPercentVoltage:
	sendMessage(LM_API_VOLT_T_EN | m_deviceNumber, NULL, 0);
	break;
default:
	return;
}

I was looking for something that implemented the kPosition control mode…

TIA,

Mike

Is this what you are asking about? http://www.chiefdelphi.com/forums/showthread.php?t=82458

Yup, something like that. Unfortunately, he never got an answer.

TIA,

Mike

Ok, here is my best shot at answering this. We literally got it working about 4 hours ago, and even then it would stop working randomly (no change of code in between). Your mileage may vary.

We attached a 100k potentiometer (we had no 10k’s which the manual calls for) to the signal pin of the jaguar.

First add this to the switch statement in InitJaguar()

case kPosition:
	sendMessage(LM_API_POS_EN | m_deviceNumber,NULL,0);
	break;

This sets the jaguar into position mode. Again, not sure if this is right, I’m just going through everything I changed.
Initialize the CANJaguar object.

My line looks like Kicker = new CANJaguar(6,CANJaguar::kPosition); The 6 is the CAN ID.

Then I have in my teleop init portion the following. I put it there because it didn’t seem to work while in disabled. I think its because you cannot send CAN frames because that could be used to make a motor move. And if you are disabled, this is against the rules :).

	Kicker->SetPositionReference(CANJaguar::kPosRef_Potentiometer);

Kicker->ConfigPotentiometerTurns(1);
Kicker->ConfigNeutralMode(CANJaguar::kNeutralMode_Brake);

Wait(.001);
Kicker->SetPID(300,.001,0);
Kicker->EnableControl();

Note mine are pointer references, so you might need to use the . operator instead. After some experimenting the first line must be first. Otherwise you get errors, but if you enable/disable the robot a few times it starts working.
My PID constants are not tuned, but it gets the motor moving at a reasonable rate. We are using a CIM with a 9:1 or a 12:1.

I put that wait(.001) in there because it seems that it fails less. I’m thinking maybe the bus needs some time to clear or something, I honestly have no idea.

Then in your teleop or autonomous use the Set method. Values are between 0 and 1 I think. I’m not sure if it includes -1 to 0. My guess is no because the Get returns a float between 0 and 1.

If you post questions I’ll try my best to answer.

Once again, I just got this working so I may be wrong. I am just telling you most of my steps I took to get it working.

A little background on the 10k potentiometer value in the manual:

The Luminary Micro ARM processor that’s in the Jaguar operates off of 3.3v, but the ADC is only 3v tolerant. They have a 1k resistor connected in series to the power pin on the pot input on the Jaguar, so you have to use a 10k pot to cause a voltage drop across the 1k resistor of .3v and the voltage drop across the entire potentiometer of 3v.

By using a 100k pot instead of a 10k, you’re causing a voltage drop of 3.27v across the potentiometer. This means that if you pull the pot all the way down to its minimum resistance, the ADC is experiencing 3.27v, which is .27v greater than it was rated for. This might be why you had sporadic results.

If you don’t have a 10k pot on hand, don’t use a lower value, as that will cause more current to flow, which is also not necessarily good. If you have some spare resistors lying around, try putting them in series or parallel with the two extremes of the potentiometer to achieve 10k. This may reduce your resolution, but it won’t break the Jaguar. If you don’t have any resistors, wait until the next day.

This is just my take on it, if it works fine for you, go for it, but it may or may not be risky.

The added voltage ran across my mind, but the potentiometer was mounted in some C channel since it was previously a throttle control for the 2008 robot. So there are physical stops that prevent it from going under .4 and over 2.8.

Also the the original poster, if you post what code you have currently, we could help you debug it better.

I just responded to that thread. If that doesn’t answer your question, please follow up.