Sudden Initial Motor Movement with Position Control

Questions about using encoders with the Roboclaw product line
Post Reply
Crone
Posts: 2
Joined: Wed Jun 10, 2020 8:49 pm
Sudden Initial Motor Movement with Position Control

Post by Crone »

Hi, I'm running into a semi-recurring problem while using the Roboclaw Python library to control a pair of motors over usb. I'm trying to have the motors follow a series of waypoints, but I constantly have to deal with a sudden initial movement before the controller returns to the desired setpoint. For the application, I'm fine with a very slow movement so I tried limiting the acceleration, velocity, and deceleration of the motor but the initial jolt appears to happen at maximum acceleration regardless of any software limits. The command I'm running is:

rc.SpeedAccelDeccelPositionM2(address,100,int(0.1*MAXV),100,e_new,0)

Where MAXV is the maximum velocity of the motor as measured in Ion Motion Studio, and where e_new is my encoder setpoint (an integer). What's confusing me to no end is that when I use the command in a script that simply moves once, I don't see this behaviour. But when I have the command in a for loop to follow the trajectory, I see the jolt almost every time.

Below I've attached an image showing the setpoint I'm sending to the motor (e_new), as well as the measured encoder value for the motor (rc.ReadEnc2(address)[1]).

Additionally, sometimes the motor will move to the maximum or minimum set encoder value during the jolt, as if it were the new setpoint. This occurs more rarely, and could just be a coincidence, but figured it was worth mentioning just in case!

Cheers for any advice in advance.
Attachments
Setpoint vs Measured Encoder Readings
Setpoint vs Measured Encoder Readings
Pos_test_enc.png (16.88 KiB) Viewed 4537 times
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Sudden Initial Motor Movement with Position Control

Post by Basicmicro Support »

My suspicion is the roboclaw thinks it is somewhere other than where you think it is when you first start your program. You should always check the current position or home the motor before making your initial movement.
Crone
Posts: 2
Joined: Wed Jun 10, 2020 8:49 pm
Re: Sudden Initial Motor Movement with Position Control

Post by Crone »

Basicmicro Support wrote: Thu Jul 09, 2020 8:17 am My suspicion is the roboclaw thinks it is somewhere other than where you think it is when you first start your program. You should always check the current position or home the motor before making your initial movement.
Thanks for the quick response!

Digging through the forums, I believe that I'm encountering the issue discussed here regarding the use of speed and position commands in the same script. I initially home the motors manually using speed commands, and then use position in the operation shown in the plot in the initial post. I'm going through my code changing to entirely use a single command, but I noticed that I intermittently encounter issues when using SpeedDistance and SpeedAccelDeccelPosition commands together. Under the hood, is SpeedDistance utilising velocity control rather than position control? If so, should I avoid using it as well as SpeedM1 or SpeedM2?

I also wanted to ask if you had any recommendation on using SpeedAccelDeccelPosition in place of Speed. Right now, I'm planning to just use setpoint far from my current location with a max velocity equivalent to my desired velocity. The problem with this is that I've got to consider my current location and desired direction and have a set of if statements to check which command I then need to call. It seems doable to me, but I was wondering if there was a cleaner way to go about doing it?

Another question I had (just for curiosity's sake): why is it that Position control needs some additional internal variable to monitor current position separate to Speed commands? In Basic Motion Studio, the encoder count seems to keep track of my current location when I use speed commands. Is there any way to access this hidden internal variable and potentially update it if I perhaps wanted to combine speed and position commands in the future?

Cheers!
Crone
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Sudden Initial Motor Movement with Position Control

Post by Basicmicro Support »

Make sure you are using Basicmicro Motion Studio and have the latest firmware installed 4.1.34. That problem was fixed a long time ago, so if you have it, it means you have old firmware or it isnt that problem. That problem was fixed by updating the position internal variable whenever switching from non-position commands to position commands. It is done automatically.

If you are doing point to point movement you should use the Position command(s). Position moves always move point to point(eg accel, constant speed, decel). If you want to chain together multiple movements without stopping between command then you should use the distance or regular speed commands.

The position system interpolates the next 1/300 of a second position to move to. This takes the encoder out of the equation for the most part(eg it works reasonably well even with poorly tuned PIDs). This also prevents situations where if at the end of a position move the encoder can't reach the precise location the movement still completes without locking up the controller.

Post Reply