Python examples misunderstanding

General discussion of using Roboclaw motor controllers
Post Reply
kkostyuk
Posts: 3
Joined: Tue Mar 01, 2016 8:59 am
Python examples misunderstanding

Post by kkostyuk »

I have USB Roboclaw 2x15a v4.1.16 connected to Linux
Encoders are have 3200 pulses per rotation, 200 RPM, max speed (200 / 60) * 3200 = 10 666 QPPS
Wheel have D = 90mm, L=Pi*D=282,6mm

If i would like rotation speed 0.5 m per second S=(500mm / 282,6mm)*3200pulses=5661pulses per second
And i would like drive 3 meters Distance = (3000 / 282,6)*3200 = 33 970

I try to example roboclaw_speedacceldistance.py, but delete loop
And have some problem
1. I change speed and acceleration, but speed not equall
2. After finish motors not stop.
What i'm doing wrong?

Code: Select all

roboclaw.Open("/dev/ttyACM0",115200)

address = 0x80

print roboclaw.ReadVersion(address)
roboclaw.ResetEncoders(address)
displayspeed()
print 'Start'

roboclaw.SpeedAccelDistanceM1(address,5660,5660,33900,1);
roboclaw.SpeedAccelDistanceM1(address,5660,0,0,0);

buffers = (0,0,0)
while(buffers[1]!=0x80 and buffers[2]!=0x80):   #Loop until distance command has
    displayspeed()
    buffers = roboclaw.ReadBuffers(address)

print 'End'
Program output:

Code: Select all

# ./roboclaw_enc_test.py
(1, 'USB Roboclaw 2x15a v4.1.16\n')
Encoder1: 000000 Encoder2: 000000 Speed1: 000000 Speed2: 000000
Start
Encoder1: 000000 Encoder2: 000000 Speed1: 000017 Speed2: 000000
Encoder1: 000008 Encoder2: 000000 Speed1: 000090 Speed2: 000000
Encoder1: 000028 Encoder2: 000000 Speed1: 000197 Speed2: 000000
Encoder1: 000063 Encoder2: 000000 Speed1: 000327 Speed2: 000000
....
Encoder1: 033759 Encoder2: 000000 Speed1: 010848 Speed2: 000000
Encoder1: 033867 Encoder2: 000000 Speed1: 010846 Speed2: 000000
Encoder1: 034012 Encoder2: 000000 Speed1: 010848 Speed2: 000000
Encoder1: 034120 Encoder2: 000000 Speed1: 010846 Speed2: 000000
Encoder1: 034229 Encoder2: 000000 Speed1: 010849 Speed2: 000000
Encoder1: 034338 Encoder2: 000000 Speed1: 010851 Speed2: 000000
....
Encoder1: 045043 Encoder2: 000000 Speed1: 010088 Speed2: 000000
Encoder1: 045078 Encoder2: 000000 Speed1: 009742 Speed2: 000000
Encoder1: 045103 Encoder2: 000000 Speed1: 009348 Speed2: 000000
Encoder1: 045107 Encoder2: 000000 Speed1: 008916 Speed2: 000000
End
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Python examples misunderstanding

Post by Basicmicro Support »

There are two things going on here.

1. Reading the Speed value returns the average speed of the controller(over the previous second). If you want the instantaneous speed read the ISpeed value. This value is the speed since the last reading of the encoder(eg 1/300th of a second).

2. When you use a distance command you need to calculate how far the motor is going to turn when you slow down. If you tell the motor to stop instantly it isnt going to(physics and all that). You should use a decceleration value just liek you used an acceleration value when you set the speed(eg 5660 in this code).

You need to do some math to determine the distance it will take to decelerate. We have a post that explains it here: http://forums.ionmc.com/viewtopic.php?f ... tance#p158

Your duplicate postings will be deleted. Please dont multi post the same question in the future.
kkostyuk
Posts: 3
Joined: Tue Mar 01, 2016 8:59 am
Re: Python examples misunderstanding

Post by kkostyuk »

I try this calculation method, as you recommend
D = 33900
speed = accel = deccel = 5660

Code: Select all

//D, speed, accel and deccel are defined by you
float d1 = (speed*speed)/(2*accel)
float d2 = (speed*speed)/(2*deccel)
uint32_t dT = d1+d2
if(dT>D) {
	d1 = d1/dT * D;
	d2 = d2/dT * D; }
else{ 
	d1 = D-d2; }
As result
d1 = 2830
d2 = 2830
dT = 5660

dT < D and
d1 = D - d2 = 31070

Change python example

Code: Select all

print 'Start'

roboclaw.SpeedAccelDistanceM1(address,5660,5660,31070,1)
roboclaw.SpeedAccelDistanceM1(address,5660,0,2830,0)

buffers = (0,0,0)
while(buffers[1]!=0x80 and buffers[2]!=0x80):
    displayspeed()
    buffers = roboclaw.ReadBuffers(address)

print 'End'
But result the same, roboclaw not stop motors

Code: Select all

...
Encoder1: 029918 Encoder2: 000000 Speed1: 010336 Speed2: 000000
Encoder1: 030055 Encoder2: 000000 Speed1: 010330 Speed2: 000000
Encoder1: 030158 Encoder2: 000000 Speed1: 010333 Speed2: 000000
Encoder1: 030261 Encoder2: 000000 Speed1: 010332 Speed2: 000000
...
Encoder1: 041640 Encoder2: 000000 Speed1: 010146 Speed2: 000000
Encoder1: 041696 Encoder2: 000000 Speed1: 009814 Speed2: 000000
Encoder1: 041736 Encoder2: 000000 Speed1: 009504 Speed2: 000000
Encoder1: 041769 Encoder2: 000000 Speed1: 009148 Speed2: 000000
Encoder1: 041779 Encoder2: 000000 Speed1: 008753 Speed2: 000000
End
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Python examples misunderstanding

Post by Basicmicro Support »

Have you confirmed the Roboclaw is controlling the speed correctly using IonMotion? If it isnt, then this isnt going to work. The first thing is to make sure speed control is working fully.
kkostyuk
Posts: 3
Joined: Tue Mar 01, 2016 8:59 am
Re: Python examples misunderstanding

Post by kkostyuk »

Sorry for long replay!
I'm install application IonMotion to my WinPC and connect RoboClaw successfully.
I don't see any buttons start or set position ...
Do you have any instructions how to use IonMotion?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Python examples misunderstanding

Post by Basicmicro Support »

The Position Settings button on the Left will open the window that lets you setup and test position control. You will need to tune the settings correctly for your motor. There is a section in the Roboclaw manual that talks about manually tuning and using the autotuner starting on page 56.

Have you confirmed your encoders are being read correctly? If not, first open the PWM settings window and slide the motor slider up to start the motor moving forward(slowly). Then check the encoder value at the top of the screen. It should be increasing. If it is decreasing your encoder wiring is backwards relative to the motor. Swap the encoder wires or swap the motor wires. Then go to the Position Settings window and go through the steps described in the manual.

Post Reply