values for absolute encoders

Questions about using encoders with the Roboclaw product line
Post Reply
hachiko
Posts: 5
Joined: Sat Apr 09, 2016 3:10 pm
values for absolute encoders

Post by hachiko »

Hello,

I have a V4 2x5A that I'm controlling through serial. I have a gear motor with an absolute encoder on it. When I'm driving it with M1Forward(30), and log current, position, speed and direction (using readCurrents, readM1encoder and readM1speed through the python lib), I get the following for a 360deg turn:

I= 20 Pos= 175 Spd=-6928 Dir=1 Status= 130
I= 19 Pos= 1519 Spd= 1706 Dir=0 Status= 128
I= 19 Pos= 1937 Spd= 1777 Dir=0 Status= 128
I= 20 Pos= 1944 Spd= 1402 Dir=1 Status= 130
I= 20 Pos= 1943 Spd= 1124 Dir=0 Status= 130
I= 20 Pos= 1942 Spd= 884 Dir=0 Status= 130
I= 20 Pos= 1940 Spd= 690 Dir=1 Status= 130
I= 20 Pos= 1939 Spd= 549 Dir=1 Status= 130
I= 20 Pos= 1938 Spd= 429 Dir=1 Status= 130
I= 17 Pos= 1937 Spd= 330 Dir=1 Status= 130
I= 20 Pos= 1935 Spd= 265 Dir=0 Status= 130
I= 20 Pos= 1935 Spd= 205 Dir=1 Status= 130
I= 20 Pos= 1934 Spd= 153 Dir=1 Status= 130
I= 19 Pos= 1932 Spd= 123 Dir=0 Status= 130
I= 21 Pos= 1931 Spd= 89 Dir=1 Status= 130
I= 21 Pos= 1930 Spd= 66 Dir=1 Status= 130
I= 21 Pos= 1928 Spd= 49 Dir=0 Status= 130
I= 21 Pos= 1928 Spd= 35 Dir=1 Status= 130
I= 22 Pos= 1927 Spd= 19 Dir=1 Status= 130
I= 23 Pos= 1925 Spd= 11 Dir=1 Status= 130
I= 21 Pos= 1924 Spd= 4 Dir=1 Status= 130
I= 20 Pos= 1923 Spd= 0 Dir=1 Status= 130
I= 23 Pos= 1922 Spd= -4 Dir=1 Status= 130
I= 26 Pos= 1921 Spd= -8 Dir=1 Status= 130
I= 21 Pos= 1920 Spd= -10 Dir=0 Status= 128
I= 23 Pos= 1918 Spd= -11 Dir=0 Status= 130
I= 20 Pos= 1918 Spd= -8 Dir=0 Status= 130
I= 19 Pos= 1916 Spd= -19 Dir=1 Status= 130
I= 20 Pos= 1916 Spd= -15 Dir=1 Status= 130
I= 20 Pos= 1916 Spd= -16 Dir=1 Status= 128
I= 20 Pos= 1914 Spd= -16 Dir=1 Status= 130
I= 20 Pos= 1912 Spd= -16 Dir=0 Status= 130
I= 22 Pos= 1911 Spd= -21 Dir=1 Status= 130
I= 20 Pos= 1912 Spd= -17 Dir=1 Status= 128
I= 20 Pos= 1910 Spd= -18 Dir=1 Status= 130
I= 20 Pos= 1909 Spd= -18 Dir=1 Status= 130
I= 19 Pos= 1908 Spd= -23 Dir=1 Status= 130
I= 20 Pos= 1907 Spd= -18 Dir=0 Status= 128
I= 19 Pos= 1906 Spd= -18 Dir=1 Status= 130
I= 19 Pos= 1905 Spd= -23 Dir=1 Status= 130
I= 20 Pos= 1904 Spd= -19 Dir=1 Status= 130
I= 20 Pos= 1903 Spd= -18 Dir=0 Status= 130
I= 20 Pos= 1902 Spd= -18 Dir=1 Status= 130
I= 20 Pos= 1902 Spd=-3829 Dir=1 Status= 128
I= 21 Pos= 152 Spd=-6871 Dir=1 Status= 130
I= 23 Pos= 1726 Spd= 1830 Dir=0 Status= 128
I= 24 Pos= 1940 Spd= 1696 Dir=0 Status= 128
I= 19 Pos= 1944 Spd= 1339 Dir=1 Status= 130

Included a bit extra to see the full cycle.
The 10k pot is supposed to have 270 deg range, but can continuously rotate - just has a jump/gap. I can see it's wrong, even with a correcting resistor in series. However, I'm more confused by the speed - I'm trying to get the values to do PID/position control, and don't know what to do with non-constant speed, since I'm driving the motor constantly.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: values for absolute encoders

Post by Basicmicro Support »

The pot must produce between 0v and 2v output signals. Anything above 2v will be clipped to 2v by the A/D converter.

Read the absolute encoder section in the manual. It explains how you need to wire up a pot to get the 0v to 2v range with a 5v power source(by adding a specific resistor in series with the pots positive lead).
hachiko
Posts: 5
Joined: Sat Apr 09, 2016 3:10 pm
Re: values for absolute encoders

Post by hachiko »

Thank you very much!

I got the pot working, I had wired it wrong - the 15k resistor was in series with the pot, instead of running ground-resistor-5V through the whole pot and picking up signal from the variable part.

Now I'm trying to tune it - it's moving but it's difficult to find kp, ki, kd; I think I found a good value for QPPS (running at a lower speed multiplying) of about 40k. Right now the motor moves but stops well before reaching the desired position.

I tried to run the IonMotion software but I get "unhandled exception" when I tried connecting. This is a 2x5A V4 controller, and it just does serial - does the control software work with this board?

I looked at http://forums.ionmc.com/viewtopic.php?f=3&t=69 but it only talks about QPPS and not the other values too. Any pointers?

Thanks again!
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: values for absolute encoders

Post by Basicmicro Support »

IonMotion only works with the USB models.

Do you know what firmware version is on your board? If its much older than 4.1.16(which it probably is since we havent sold non-USB models in a while now) I recommend you send it in for a firmware update.

When your position is falling short by alot it usually means your P is very low. Basic tuning steps are to zero I and D and keep increasing P until the motor is moving to the target psoition quickly and just starts to oscilate continuously around the target position. Then back P off to 2/3rds that value. For very low res encoders(eg absolute encoders) I recommend not setting any I. Then if you move to a position and it overshoots and moves back(but doesnt oscillate significatnly, that would indicate P is still too high) start adding D until it doesnt overshoot any more and just stops as it reaches the target position.
hachiko
Posts: 5
Joined: Sat Apr 09, 2016 3:10 pm
Re: values for absolute encoders

Post by hachiko »

I think it was updated already. Printing version gives me 'USB Roboclaw 2x5a v4.1.6\n\x00O'

Do I need to set velocity PID values too (command 28)? When I don't set P for that, it's always very far off - page 56 of the manual, in "Position Manual Calibration Procedure" says that velocity values can be set to 0 though.

When I set P for both velocity and position to the same value, I get somewhere with P=4000000. It's very far off though. My set-up is below. With this value for P, going to 200 stops well short (500) and then going directly to the other end, close to 1200, only gets me to around 800. If I keep sending the same 65 command, it gets closer, but never in one shot.

If I double P, then it gets closer to the bottom end and stops (but still not anywhere close to 200), but at the top end it starts oscillating and getting closer - 600 - 500 - 800 - 700 - 1000 and so on until it goes out of the range.
Setting D doesn't really help. QPPS = 44000

I'm surely doing something wrong, I can't figure out what.

-----------------

I have a ~340 deg pot:
http://www.digikey.com/product-search/e ... s=p12426ct

Connected directly to the shaft of a 180RPM gearmotor:
https://www.pololu.com/product/1163

After fixing the resistor, the range reported by the encoder is between 100 and 1500, and reading the encoder i'm not seeing issues with that anymore.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: values for absolute encoders

Post by Basicmicro Support »

4.1.6 is pretty old now. 4.1.16 is the current version.

I dont beleive 4.1.6 had the CRC16 checksum change yet so you will need to use the older sum'd checksum command format.

With pots Velocity control is usually not very useful. To low a resolution for meaning full velocity information. I recommend leaving The PID for velocity at 0. You still need to set a QPPS value for your motor. What value have you calculated for QPPS? and did you measure it manually or calculate it from motor specs?
hachiko
Posts: 5
Joined: Sat Apr 09, 2016 3:10 pm
Re: values for absolute encoders

Post by hachiko »

You are great!

Yes the CRC16 isn't there, the sample lib on the pololu site had the old style. Can I do the upgrade myself?

The problem seems to have been QPPS - I used the formula from http://forums.ionmc.com/viewtopic.php?t=193
I got ~4500, and now it works.

Last question - when i ask it to move from one end of the range to the other, it starts working OK with no oscillation at around P = 6000000. I set P al the way to the max in fact and never got oscillation.
If I try to move in increments of say 20 though, it's very dicey - is that because of the analog resolution? the deadzone right now is set to 5. Again I haven't had to set D yet.

Thank you very much again, you've been of great help!
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: values for absolute encoders

Post by Basicmicro Support »

THe units without USB have no mechanism to update themselves. We have to reprogram them here.

1. I dont recommend you run the full range to test the settings. leave a fair bit of margin on each end so you can see any overshoot.

2. How large is the distance you can move over the range of the encoder? If the distance is very large and the encoder resolution is very low you will have limited position accuracy. It also sounds like you have some slop in the encoder/motor based on your deadzone setting. Describe why you mean by "dicey" in a little more detail and I may be able to give you some advice.
hachiko
Posts: 5
Joined: Sat Apr 09, 2016 3:10 pm
Re: values for absolute encoders

Post by hachiko »

Sorry for the lack of specifics.

1) The min and max for the encoder are set to 100, 1400. The pot can rotate continuously, but there's a discontinuity in the resistance between 50 and around 1520, which corresponds to 0 degrees and ~340 degrees.

2) I made a small python program which can tell the motor to move either to 200, to 1400, or up by 20 encoder units, or down by 20 encoder units.

- When I move from 200 to 1400 or from 1400 to 200, it starts moving within 5 of that from P = 6000000.

- I can take P up until max, and there's very little change - it never overshoots, it doesn't hunt, just move straight there.

Throughout all the tests, I and D are 0. Deadzone is 3.

3) when I try to move by +-20 though, it doesn't always move. I'd go 200 -> 205 -> 213 when it should have been 200, 220, 240. Same result if I move down the range.

If I increase P in this case, it gets somewhat better, but still doesn't reach the true value by a significant amount - while at the same time still not oscillating or even overshooting.

Should I be moving D at this point?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: values for absolute encoders

Post by Basicmicro Support »

Always make sure you never let the pot roll over(eg past its dead spot). This will cause weird issues with Roboclaws control since it does not know and has no way of knowing this can happen. Your current margins should be fine to prevent this but I wanted to point that possible problem out.

Your P seems very low(91.55 after converting to fixed point(eg 6000000/65536 = 91.55) I would expect the P value to be at least 10 times higher. This would also explain why the small movements dont always move. Very low proportional.

Post Reply