Gantry robot - Communication between multiple Arduinos

I am making a classic XYZ gantry robot for picking up some test tubes using a machine vision system i wrote in Processing. The outline of the system looks something like the attached photo.

Basically a Raspberry Pi 3 as a brain, finding positions through a camera and taking inputs from a GUI on the touch screen.

For making the robot move i have bought a bunch of Ustepper S driver. For those not familiar with this board, it is basically a merge between a stepper driver and an Arduino UNO, but the new version will offload the CPU by using a separate chip for calculating acceleration and speed, thus hopefully enabling the robot to be very fast.

For the question in this topic they can be regarded as an Arduino Uno, but i will refer to them as UStepper.

I need someway of communicating between the Raspberry Pi and the Usteppers. From the Pi to the UStepper i need to send position, speed, acceleration and commands like “goToEndStop”, “closeClaw”, “openClaw” etc. From the Ustepper to the Pi i need confirmation when these commands have been executed.

I think that i can get the cables down to 2-2½m as the maximum distance. I can use as many wires as necessary, but as few as possible is desired.

So i am thinking along the lines of I2C or RS 485 (with ModBus). I2C seems to be the easiest one, since i do not need to have an RS485 translationboard inbetween the Pi and UStepper, but is the I2C robust enough?

So here is a scenario that i am afraid of: X axis are using two stepper motors to run. These need to run simultaneously, Two problems:

  1. Not being synchronous within a couple of milliseconds, 1/10 of a second are probably to high.
  2. One of the Usteppers does not get the signal because of noise or other obstacle and UStepper number two starts moving without number one.

Are wire.h (I2C lib) robust and fast enough this? Can wire.h detect if the com string has not been received by the slaves or do i need to write my own protocol to check this?

Are there another way of making this communication, that i am overlooking?

All suggestions are very welcome :smiley:

I2C was designed to communicate with on chip components. You might be able to get it to run the distance you want but it won’t be as reliable as other methods. Especially since motors induce noise into wires.

RS485 with modbus will work but can be tricky and time consuming to program.

Another option you haven’t thought of is using CAN. It uses the same physical parameters as RS485 but has more control than modbus. You can also purchase CAN shields from companies like Seeed Studio. I found the most success with this library #include <CAN.h> //https://github.com/sandeepmistry/arduino-CAN. That would be your easiest and most flexible programming option.

Be aware that using a Pi as brains poses some problems. It isn’t a real time solution. Operating systems such as Linux are very good at doing lots of different tasks but the order in which it does them is random. Sometimes it can’t get the accuracy you like for motion control applications. Motion control can be done on a PC but professional programs take control of at least 1 core of the processor from the operating system. You will have more success with something like an Uno or mkrzero since they run programs in a loop and have better real time response due to the nature of how they operate.

Palmhoej:

  1. Not being synchronous within a couple of milliseconds, 1/10 of a second are probably to high.
  2. One of the Usteppers does not get the signal because of noise or other obstacle and UStepper number two starts moving without number one.

Both of those problems would be solved if there was just a single Arduino controlling all the stepper motors.

How many steps per second do you require for the fastest motor?

...R

@Henradrie. Thank you for the suggestion on CAN i will look into that.

I am aware that the Pi is not realtime. This does not pose a problem, since all movement control (speed, acceleration and deceleration) will take place on the Usteppers (thats why they are so awesome!!!), except for the mentioned problem of starting the two motors simultaneously.

(But i might be able to overcome this problem by connecting Ustepper X one with UStepper X two and make an I/O go high indicating that they should start moving together, if communication is too slow).

I do not need to do circles or fancy interpolations like a CNC, i just need the tool to go to a position as fast as possible, once arrived i does not matter that it might take 50ms to receive the new order... but i can actually send the new position to each controller, before it is done executing the move, so it only need one go bit, to execute the next position, when the Pi get the hasArriwed bit from each controller.

@Robin2 I do not know how many steps i need, but i know that when microstepping on previous projects, using the accleStepper.h library and a ChipKIt (or Arduino Due) i hit the libraries step/sec limit way before i hit the hardwares speed capability. And it gets rather jerky in its acceleration curves and pushed to far it will jerk and make the motor overstep. The library is not meant for high speed pulsing of 3 steppers. I have seen people go crazy fast with one stepper and own code on arduino, but i do not have the programming skills to go under the hood of Arduino IDE to do so. And they only do it with one stepper. But if you know of a library that can do this i will be thrilled :smiley:

The above mentioned limits is why i am so thrilled for the new Ustepper S-line, because it offloads the acceleration calculation, potentially promising very high speeds. And you get closed loop system with encoder, so it should not skip, which again faires good for pressing the stepper close to its speed limits.

Palmhoej:
@Robin2 I do not know how many steps i need, but i know that when microstepping on previous projects, using the accleStepper.h library and a ChipKIt (or Arduino Due) i hit the libraries step/sec limit way before i hit the hardwares speed capability. And it gets rather jerky in its acceleration curves and pushed to far it will jerk and make the motor overstep. The library is not meant for high speed pulsing of 3 steppers. I have seen people go crazy fast with one stepper and own code on arduino, but i do not have the programming skills to go under the hood of Arduino IDE to do so. And they only do it with one stepper. But if you know of a library that can do this i will be thrilled :smiley:

You are correct that the AccelStepper library has speed limitations. I believe that's because it uses floating point maths.

This link has a simple system for DIY acceleration and I use the idea for the three steppers on my small lathe. In simple terms acceleration is just a sequence of changes to the interval between steps.

If you want 3 motors to move in sync - meaning that motorA does 327 steps, motorB does 1213 steps and motorC does 57 steps all in the exact same time - then figure out the acceleration for the fastest motor and slave the others from it.

For high step rates you will probably want to use the digitaWriteFast library, or perhaps direct port manipulation.

...R

Thank you for the answer. I did think about writing it myself, but i am sure that if one dove into this task it will present itself with a lot of new challenges. Not that i mind challenges, but it takes time that i do not have… and i also have the feeling that there might be a reason that i have not seen any code able to do this task for two steppers, i mean it is a very common task to place something in an XY coordinate? :slight_smile:

Here is another option you can use for motion control.

https://dynomotion.com/KFLOP.html

It takes care of all you problems for you and is much more capable than an arduino. Arduino is a really neat tool to use but is often limited by it's processing power and nature. Sometimes people stretch it's capabilities to the limits.

The board I mentioned is purpose built for motion control and will eliminate a lot of your headaches but is more expensive.

Henradrie:
Here is another option you can use for motion control.

I hope the product is faster than their website. I got tired of waiting for it :slight_smile:

...R

That is a way to go and on my old CNC router i used something similar (Ethernet Smoothstepper) with great success. I am a little bit unsure how to get the information from Processing and down to a board like this, though. How would one do this?

But i still like the idea of what i am trying to achieve with this setup better, since the motor unit becomes a single entity only requiring com and 24v, that does its own calc and closed loop controlling.

And thanks for all the inputs, it is appreciated. Keep em coming.