Slow communications Latency using Packet Serial

General discussion of using Roboclaw motor controllers
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Slow communications Latency using Packet Serial

Post by DillonMEK »

Hi

I am using the RoboClaw controllers to run all my actuation on a project.

The project consists of a Steward Platform atop a kiwi drive omni directional base

I am controlling 6 linear actuators for the platform, and 3 DC motors for the base
I am using an Adafruit ESP32 Feather for the MCU and have been using the Arduino libraries

The problem I am currently trying to solve is that I am getting a 30ms latency on each serial communication between the MCU and the RoboClaws - with 9 actuators this is adding up to 270ms for each command cycle, which is not functional. This gets worse when I try and request information from the RoboClaws.

I had been running previously off an AVR AtMega2560, I experienced a similar problem until I split the base and platform control over 2 Serial channels, but that doesn't seem to be fixing it this time (and it doesn't solve the initial problem with the source of the latency) - any help on this would be greatly appreciated.

Here are the drive functions:

Code: Select all


//kiwi drive base driving function

void driveEncBase()
{
  roboclaw2.SpeedM1(CLAW4ADR, kiwi[0]);
  roboclaw2.SpeedM2(CLAW4ADR, kiwi[1]);
  roboclaw2.SpeedM1(CLAW5ADR, kiwi[2]);
}

// Stewart Platform drive to position function
void moveToPos()
{
  
  for(int i = 0; i <3 ; i++)
  {
    roboclaw.SpeedAccelDeccelPositionM1(address+i,0,linearV,0,targetPos[(2*i)],0);
    roboclaw.SpeedAccelDeccelPositionM2(address+i,0,linearV,0,targetPos[(2*i)+1],0);
  }
    
}

void serialDrive()
{
  mapVector();
  stewartPos(transPos[XX],transPos[YY],transPos[ZZ],euler[A],euler[B],euler[C]);
  kiwiDrive(kiwiA, kiwiV, kiwiR);
  int tm2 = millis(); //this is to check serial latency only, comment out once fixed
  driveBase();
  Serial.println(millis()-tm2);
  tm2 = millis();
  moveToPos();
  Serial.println(millis()-tm2);
}

UPDATE:
When I set the timeout to 1000 instead of 10000 when defining the roboclaws, the latency drops to 10ms - the esp32 therefor is timing out with communicating to the RoboClaws - given the trouble I was having with requesting info from the controllers, it would seem that the ESP32 isn't reading data back from the controllers?

UPDATE 2:
Even with the timeout set to effectively zero, the latency on the Platform drive is still around 8ms on each communication cycle (with the encoders and actuators not currently connected) - so around 83ms for all nine control commands (I have ran it wirelessly, connected to all the actuators, so the control commands are getting from the ESP32 to the Roboclaws just fine)

Dillon
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Re: Slow communications Latency using Packet Serial

Post by DillonMEK »

UPDATE 3:

Have tried different baudrates and still get the same issue
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Slow communications Latency using Packet Serial

Post by Basicmicro Support »

The arduino library is setup to retry a command up to 3 times if it does not receive an ack from the Roboclaw. The time for each try is 10ms. Since you are seeing 30ms delay I can assume that your commands are being retried 3 times. THis would lead me to look at the receive line connected to the arduino. Are you getting any data back on it. Is it wired correctly? We have not tested the ESP32 though I have had other customers use it.

If you are using multiple Roboclaws on a single serial port(eg back when you used the Mega2560) and the pullup was not strong enough you could have had problems reading the ack byte which would have caused the retries/timeouts which cause the excessive 30ms delay.

Changing the timeouts to 0 will still have an effective delay of a couple ms since the commands will be resetn multiple times. Focus on the receive line. If you are having trouble receiving data from the Roboclaw then that explains the ack failing. Look at the signals on a scope(provide a screen shot if you can). How do you have everything wired? Are you using the latest version of the arduino library?
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Re: Slow communications Latency using Packet Serial

Post by DillonMEK »

The wiring all appears to be correct

The esp32 uses 3v logic - I haven't checked for updates since last October, but that should still be up to date - that it is happening on every board and every packet sent leads me to conclude the problem is on the ESP32 end

I have it wired s1 > tx s2 > rx, the connections all appear sound, and the data sent to the boards is getting received and processed with no issue - the platform and base is doing what it is told, but with the 10ms timeout I only get 4 frames per second of control signal, with it set to 0, the best I can get is still around 10 frames per second. Ideally I want 30, and there are other communication functions that have to occur when all that is going on, such as sending telemetry back to the server - to this end fixing the communication issues with the RoboClaws would be very useful too, as I would like to log power usage and live readings of the encoders etc.

Other things I have tried is only running the platform or base RoboClaws, and just a single board running a couple of motors with encoders

If I can't resolve the ESP32 comms issue I may have to set it up with the ESP forwarding the control vector to an Arduino nano and using the nano just to drive the drivers! Obviously this is a lot more work that should really be unnecessary, so geting the ESP32 to listen to the RoboClaws is still my ideal solution.
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Re: Slow communications Latency using Packet Serial

Post by DillonMEK »

UPDATE 4:

While the RoboClaw data sheet says it automatically allows for 3v or 5v logic, the ESP32 doesn't seem to like what it is putting out

Using a logic level converter I have got much better results - with the timeout set to the standard 10ms, I am getting less than 1ms for the 3 packets to the base roboclaws, but I am still getting 45 - 60ms for the 6 packets to the platform roboClaws - obviously heading in the right direction, but still could do with fixing what ever is going on with the platform communication. It makes no diff if I set the timeout to 0, I still get the same.

I am currently running at 57600 Baud, I will try a couple of lower settings
I also haven't attempted a packet request from the boards to the MCU
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Slow communications Latency using Packet Serial

Post by Basicmicro Support »

The the Roboclaw boards individually connected to a uart(one each) or are you bussing multiple roboclaws to the same uart on the ESP?

Also a simple 3.3v pull-up on the RX pin may be sufficient instead of the level converter. Check the actual signal levels on the RX line connected and not connected to the ESP? Is the ESP dragging the signal line lower than it should when connected. The Roboclaw outputs a 3.3v signal.
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Re: Slow communications Latency using Packet Serial

Post by DillonMEK »

I am bussing 5 Roboclaws on one serial channel Serial(1) - which is a hardware serial

I haven't had access to an oscilloscope while trouble shooting this particular issue, but the ACK delay seems to have mostly gone with using the level converter, which I had one of in my kit, but yes I will investigate further and maybe go with the simpler solution on the next iteration, as I am just trying to get the damn thing functional for a demonstration on the weekend!
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Re: Slow communications Latency using Packet Serial

Post by DillonMEK »

Tried 10k pullup resistors on the UART pins without using the logic level converter, this didn't work
DillonMEK
Posts: 10
Joined: Sun Sep 17, 2017 11:01 pm
Re: Slow communications Latency using Packet Serial

Post by DillonMEK »

Have it working now with 3 Roboclaws on one channel, 2 on the other, 12k pullup resistors, and time out set to 5ms - this gives me a latency ranging 4 - 18 ms, averaging around 10ms, so it is obviously still dropping some packets on each cycle, but that is still fine for the max 30fps I am after
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: Slow communications Latency using Packet Serial

Post by Basicmicro Support »

1. If you are using multiple Roboclaws on a single serial port Im assuming you have multi-unit mode enabled. If not this would be causing the ack failures(due to interference from the different Roboclaws. If they are in multiunit mode you will need a pullup resistor on the RX line from your computer(eg the line that goes to the Roboclaw S2 pins). Also 10k pullups are the minimum we recommend for this pullup. For higher baudrates than 38400 I would recommend 4.7k or 1k.

2. What happens to latency if you only use a single Roboclaw? My guess is it goes way way down(1ms or less). This is probably because in multi-unit mode if your dont have the pullup or you dont have a strong enough pullup the commands will never get an ack back from the Roboclaw. This will cause our libraries(arduino or python) to retry upto 3 times. Each time will add a 10ms timeout so around 30ms of latency between commands you send and you wont be able to read any data back from the Roboclaw.

Post Reply