library bug found

General discussion of using Roboclaw motor controllers
jimt
Posts: 17
Joined: Wed Dec 07, 2016 7:27 am
library bug found

Post by jimt »

When using the function: SpeedAccelDccelPositionM1 the value of speed has no effect. You can substitute any value for speed, even zero, but the speed of moving to position does not change. I am using the python library.

Thanks
Jim
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: library bug found

Post by Basicmicro Support »

Does it work in IonMotion(eg when testing in the Position Settings window it uses that command for M1)?
Did you tune the Velocity PID as well as the Position PID?
Are you using the latest firmware(4.1.19).

Please show your code.

Thanks.
jimt
Posts: 17
Joined: Wed Dec 07, 2016 7:27 am
Re: library bug found

Post by jimt »

First, the wheel of my motor is suspended in air.
Also I noted the following when running the code below:
The first time I run the code (following a roboclaw power cycle) the motor speed is very slow and all subsequent times I run the code the motor speed is very fast. Changing the speed parameter has no affect.
Lastly, it always ends at the correct position.

Does it work in IonMotion(eg when testing in the Position Settings window it uses that command for M1)?

it finds position in inIonMotion but not sure about speed settings.

Did you tune the Velocity PID as well as the Position PID?

Yes, I used the auto tune for both velocity and position, then saved settings.

Are you using the latest firmware(4.1.19).

Yes, it is the latest firmware.

Please show your code.
`

Code: Select all

import roboclaw
import time
import os

port = ''

def findPort():
    global port
    if os.path.exists('/dev/serial/by-path/platform-3f980000.usb-usb-0:1.2:1.0'):
        port='/dev/serial/by-path/platform-3f980000.usb-usb-0:1.2:1.0'
        return True

    print 'Motor Controller port not found'
    return False

def Open():
    if(not findPort()):
        return False
    
    ok = roboclaw.Open(port,115200)
    if(ok): print("roboclaw Opened")
    else:
        print("roboclaw Failed to Open")
        return False

    time.sleep(1.5)
    try:
        version = roboclaw.ReadVersion(0x80)
        if(version[0]==False):
            print("ReadVersion Failed")
        else: return True
    except Exception, e:
        print("Exception: ReadVersion Failed")
        return False   

def Close():
    roboclaw.Close()
    return
        
def getVersion():
    return roboclaw.ReadVersion(0x80)

def getPosM1():
    enc = roboclaw.ReadEncM1(0x80)
    if(enc[0]==True):
        return enc[1]         
    else: return 0

def moveSpeedAccelDccelPos(accel,speed,dccel,position):
    roboclaw.ResetEncoders(0x80)
    print('start pos=' + str(getPosM1()))
    roboclaw.SpeedAccelDeccelPositionM1(0x80,accel,speed,dccel,position,0)
    buffers = (0,0,0)
    while(buffers[1]!=0x80): # Loop until distance command expired
        buffers = roboclaw.ReadBuffers(0x80)

    return 1

def main():
    if(Open()):
        resp = moveSpeedAccelDccelPos(1000,1000,1000,10884) # 10884 = 1 wheel revolution
        if (resp == 1):
            print('move done, pos=' + str(getPosM1()))
        else: print('move failed')

        time.sleep(1)
        Close()
        
main()
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: library bug found

Post by Basicmicro Support »

Please re-test it using IonMotion and check if the speed is controlled properly. Note you must set the speed it will use for the movement in the appropriate field to the right of the motor control sliders.
jimt
Posts: 17
Joined: Wed Dec 07, 2016 7:27 am
Re: library bug found

Post by jimt »

in IonMotion the speed setting (under motor 1 of Position Settings Tab) does not affect the speed of rotation. However, the motor 1 slider bar under the Velocity Settings Tab seems to work well.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: library bug found

Post by Basicmicro Support »

What are your Velocity and Position PID settings when testing in the Position Settings screen?
jimt
Posts: 17
Joined: Wed Dec 07, 2016 7:27 am
Re: library bug found

Post by jimt »

using the autotune I get the following values:
Velocity P = 6520
Velocity I = 78.25
Velocity D = 0

Position P = 10644
Position I = 0
Position D = 0

The motor is running smooth under these settings and I have tried other settings using manual tune.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: library bug found

Post by Basicmicro Support »

I've hooked up a motor and after autotuning I've run tests in IonMotion. My maximum speed is 40000(eg the QPPS). I set the speed to 10000 and then did some position movements and the correct speed was used(eg 10000). Changed to 2500 retested and same thing. I used the graphing function to confirm as well as just physically looking at the motor running at the different speeds(the speed difference was obvious).

I swapped the motor between both channels and retested. Both channels worked the same.

My Vel PID values are:
P 1861
I 322
D 0

Pos PID values are
P 8000
I 0
D 0

Range is set to 0 to 40000

Your values dont seem out of the ordinarry.

What is are your position ranges set to?
jimt
Posts: 17
Joined: Wed Dec 07, 2016 7:27 am
Re: library bug found - RESOLVED -

Post by jimt »

Temporary fix. Do not call ResetEncoders() function before position move.
jimt
Posts: 17
Joined: Wed Dec 07, 2016 7:27 am
Re: library bug found

Post by jimt »

Has this python library issue been fixed yet? Or is this a firmware issue?
Thanks

Post Reply