What is the best architecture for controlling 4 dc motors in a 4WD car?

Good morning. I hope everyone is ok during this pandemic crisis. I’m in quarantine at home as most of the world, so I’m running some projects in my free time.

I’ve starting to build a 4wd car based on the “OSOYOO 4WD Omni Wheel Robotic Mecanum Wheel Robot Car Platform Chassis with DC Speed Encoder Motor for Arduino/Raspberry Pi” kit. My objective is get new knowledge and tons of fun during the design and construction of an autonomous vehicle (Lidar and/or Mynt Eye 3D Stereo Camera).

I am designing the architecture and I’ve started by the motor control. Requirements are:

  • • The kit has four dc motors (gear ratio 1/75).
  • • Four mecanum wheel
  • • Each motor has a hall encoder with two phases (ie speed and direction).
  • • The control will be two TB6612FNG.
  • • I’ll be running ROS Kinetic in a raspberry PI connected to a rosmaster in a PC.
  • • Also, I will need to connect an IMU (BNO055) trough I2C, and probably at least some distance sensor (I2C or Rx/Tx).
  • • For each motor I need to provide commands for speed (maybe also acceleration). I need to get distance, angular velocity. If required, I should run PID in order to ensure all motors move at the same speed.
  • • For the set of motors, I need to provide commands for movement (eg: move forward 200mm, turn right 20°, emergency stop).
  • • Communication will be ROS Kinetic based

I would like to hear your advice and know about your experience. I’ve googled lot, during several days, but I still don’t have a clear understanding about the best way. Here some experiences from other projects:

a) Using an Arduino mega. IN: 4 signals to 4 interrupt pins. OUT: 4 pairs of speed and direction to motor controller. The Mega is connected to RB Pi trough USB (using rosserial).

b) Using four Arduino Nano, each one receiving encoder to interrupt pin and controlling his motor. The four connected to an Arduino mega trough I2C. Arduino mega connected to RB Pi trough USB (using rosserial).

c) Using a Teeny 3.2 (like a).

d) I did not find a specialized board that does this job (four motor control, encoder, PID algorithms).

Out of scope: other devices related with navigation algorithms, like the Lidar or 3d Camera should be connected to a second raspberry pi as a different node.

Can you please share your experience? I’ll start testing some configurations and check how they run (performance, stability, communication speed, free time of the processor for future tasks), but I don’t want to start from scratch.

Thanks in advance, Juan.

I've started testing with the arduino mega.

For 1 motor, it runs fine. I've used the interrupt pin17 for the encoder-A. The encoder-B goes to D7. Tomorrow I'll add the three other motors (interrupts pin 18,19 and 20) and check how it runs.

I'll need to run 4 PID routines and 4 digital input inside the loop. I'll put some traces and check with the oscilloscope how much it takes.