Mixing position and speed/distance commands

Questions about using encoders with the Roboclaw product line
Post Reply
marsrover
Posts: 8
Joined: Sun Jul 03, 2016 10:49 am
Mixing position and speed/distance commands

Post by marsrover »

I'm having some problems with the drive to position command (67). It works perfectly by itself, but when I mix it with speed and distance commands (i.e. commands 43 or 37) the motors can suddenly go to full speed. It happens rarely, maybe 1 out of 10 times. It's command 67 that causes this, but only if I previously used command 43 or 37 (maybe others, I havent' tried).

Here is an example. This is data logged with an external terminal program to rule out software errors. I wait for each command to finish executing before sending the next.

Command 67, drive M1 and M2 to position. Works fine:
8043 00000320 00000190 00000320 00000AD9 00000320 00000190 00000320 00000AD7 00 DA65

Command 43, drive M1 and M2 with speed 0 and distance 0. Works fine:
802B 00000000 00000000 00000000 00000000 01 862A

Command 67, drive M1 and M2 to position. Caused M1 or M2 (unsure which) to suddenly go to full speed:
8043 00000320 00000190 00000320 000008FF 00000320 00000190 00000320 000008FC 00 373D

I'm having trouble finding out exactly what's triggering the problem.
marsrover
Posts: 8
Joined: Sun Jul 03, 2016 10:49 am
Re: Mixing position and speed/distance commands

Post by marsrover »

After some more experimenting:

When command 67 fails it always seems to drive M1 or M2 at full speed in the wrong direction for one or a few seconds. Then the Roboclaw seems to recover. The misbehaving motor suddenly reverses direction and drives at normal speed until it reaches the correct position, which can take a while since it went very fast in the wrong direction. During all this the other motor behaves normally.

Very peculiar.
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Mixing position and speed/distance commands

Post by Basicmicro Support »

Position commands shouldnt be mixed together with other non-Position commands on the same motor.

The position commands use an internal variable to keep track of the expected next position for accelerationa nd decceleration calculations. If you move the motor using something else(Speed or PWM commands) that invernal variable is not updated which is causing the odd behavior you are seeing.

If you can explain why you need to use both Speed/distance commands and position commands togther I may be able to give you a work around.
marsrover
Posts: 8
Joined: Sun Jul 03, 2016 10:49 am
Re: Mixing position and speed/distance commands

Post by marsrover »

I would like to be able to:

1: Stop the "hold position" effect of the position command.
2: Abort a position command that is currently executing.

It seems that I can do 1 by executing command 34 "duty cycle" with argument 0 with no ill effects if the motors are already stopped. I don't think that works if they are moving though (more experiments needed).

This is going to be a "Mars rover", and I have to be able to abort a move command if I detect problems with stuck wheels etc. My current method is to simply cut power to the controller, but a better way would be nice. What I'm really after is a "stop" command. The IonMotion software has a "STOP ALL" button, and I've never seen any problems with it. What does it do?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Mixing position and speed/distance commands

Post by Basicmicro Support »

1. Yes. If the motors are holding position(already stoped) using the Duty cycle command with 0 will stop the PWM to the motors.

2. When executing a Position command a new position command can take over immediately if you set the buffer flag for that command(1 execute immediately, 0 execute when the other buffered commands for that motor are finished).

To stop the controller and hold the position, read the current position and send a new position command(with buffer set to 1). If the motor is moving very fast it may already be well past that position so you may want to tell it to stop at some position in front of the current position.

You can use the GetBuffers command to get the status of each motor.

The Stop All button in Ionmation just sends a 0 Duty cycle command like 1 above. If Stop All works on your motors the way you want then 1. should be all you need to do.

Post Reply