ROS2_Control Differential Drive Robot Project — Part 2 Electronic Hardware setup and testing motors and IMU

RoboFoundry
6 min readJan 15, 2022

--

In the first part of the article series, we went through the mechanical build of the robot but the electronic components we added during the build need to be connected with each other properly and powered up by the two batteries before we can install the software on it. We will use a schematic diagram to describe the connections and use that as our anchor to go over all the steps.

The main electronic hardware components we need to connect are:

  1. Raspberry Pi
  2. Dynamixel System — Motors, U2D2 and Power Hub [USB]
  3. IMU sensor [i2C]
  4. Lidar sensor [USB]
  5. Joystick Controller [USB]
  6. Batteries — We have two batteries one with 11.1 V to power dynamixels and another power bank with 5V to power the RPi
High Level Connection Diagram

USB Connections

For U2D2, Lidar and Joystick Controller, the connections are very simple, just plugin the right type of USB cable or adapter that is suitable for device. You may have to supply one for U2D2 and Lidar. You can pretty much choose any open USB ports out of the 4 ports available on RPi4 and when we setup the software we would have the symlink or alias mapped for those devices, and the device always gets mapped to the same name for the robot to access. This way if you switch around the port you don’t have to fiddle with the configuration files.

For batteries:

  • Dynamixel battery will be connected to power hub board using screw terminals more on this later
  • RPi power bank will be connected to RPi using a regular USB-C cable

i2C Connection for IMU/BNO055

Here is the simplest way to connect it if you purchased the one with STEMMA QT connector, no soldering required.

Sensor to RPi Pin mapping:

  1. 3.3V [Red]→RPi Pin 1
  2. GND [Black]→RPi Pin 7
  3. SDA [Blue]→ RPi Pin 3
  4. SCL [Yellow] →RPi Pin 5

After connecting the pins to RPi, power up the RPi using the power bank battery and once you connect to RPi via SSH run the following command:

sudo i2cdetect -r -y 1

You should be able to see the BNO055 show up as 28 address if the wiring is correct. If you need more help setting it up checkout this article by Automatic Addison.

You can follow the Adafruit tutorial to install the python web demo app and calibrate the sensor here.

If you want to make sure those calibration settings take effect each time you restart your RPi, follow the instructions and shell script documented in this git repo.

If you want to validate that BNO055 is generating valid output you can follow the adafruit tutorial to install additional python libraries and run the test code to make sure you are seeing good output. This is not really necessary as the calibration steps are already confirming that you are getting good data from the sensor.

Dynamixel Connections

Follow the video tutorial here to connect RPi to Dynamixel U2D2, power hub and dynamixel motors.

Here is additional e-manual that walks you through steps with diagrams on U2D2 plus power hub board assembly and wiring with Dynamixel motors.

The only challenge or struggle I had was to be able to connect the Dynamixel Battery with the power hub board. The battery comes with 2 point connector that has no corresponding socket to match on the power hub board [I wish Robotis sold parts that matched with their own parts on their site]. So I had to improvise and connect two jumper wires from the two points coming out of battery and use the two screw terminal power input option on the power hub board. You can alternatively cut the connector at the end of battery and use the wires directly to plug into the screw connector for power on the power hub board. Just make sure you don’t power up the power hub board with multiple power sources at the same time.

Thankfully, the electronic hardware setup for Dynamixel system was a breeze except for that battery connection issue. Majority of the challenges were in the mechanical build part for dynamixel rather than in the electronic hardware or software parts.

Testing Dynamixel motors

At this point you are ready to test the dynamixel motors on their own [without using RPi]. So you can connect a USB cable to your host computer where you can install Dynamixel Wizard 2.0 software. The software is pretty well documented with lots of youtube videos that walk you through the basics of how to use it.

Just to be clear as it was very confusing for me at first, here is the purpose and brief description of each Dynamixel software:

  1. Dynamixel Wizard 2.0 — this is the software you need to inspect Dynamixel motors, update firmware, calibrate or change values in the control table documented for your specific version of Dynamixel motor. this is a GUI tool. You will only need this for initial setup and tuning of motors.
  2. Dynamixel SDK — is a collection of libraries, code samples in python and C to help folks understand how to code in order to control dynamixel motors. You really won’t need this much unless you are rolling your own low level code.
  3. Dynamixel Workbench- this is a specific set of libraries built to work with Dynamixel motors at a higher level of abstraction so you are not doing low level coding but just commanding the motor at slightly higher level, for example, using it from ROS2 code. This will be the perfect set of libraries for us to leverage when we setup the Dynamixel Hardware layer to work with Differential Drive Controller from ROS2 Control. You will be using this under the hood every time you run the robot.

Basic idea is — you connect your computer running Dynamixel Wizard 2.0 via USB cable to U2D2 which is mounted on the power hub board that has both the dynamixel motors connected properly. When you launch the Dynamixel Wizard software, it will scan for existing ports at various speeds and it will detect your motors. You can change the IDs of the motors if you want using the software. You can also run the motors in Position control mode to ensure they work, just make sure to turn the Torque ON before you do that otherwise the motor will not turn. You can use the visual tool to drag or enter the angle in degrees for the motor to turn and make sure motors are working well. For our differential drive controller robot we will be using the motors in Velocity Control mode only, we don’t need to use position control mode unless you are using some sort of a robot manipulator arm on top of your robot.

While testing the motors also make sure both the motors are running in the same direction when turning in CW or CCW [clockwise or counter-clockwise] directions. You may have to change the direction of one of the motors to make sure when you move the robot forward both the motors are turning forward and when you do it reverse it is turning backward. You can attach a piece of tape to make sure you are able to see the direction clearly while testing the motors. You are in good shape if motors are running as expected and following your commands in the Dynamixel Wizard. Make sure to save your settings to each Dynamixel motor when you are done before disconnecting from your host computer. You can reconnect the U2D2 with RPi via USB cable at this point.

If you feel more adventurous, you can also download the code samples for dynamixel SDK and run the code examples from either python or C folders from command line within RPi. Just make sure the U2D2 is connected to RPi at that time.

One thing to keep in mind — Once in a while you might get error connecting to dynamixel saying no response from the motors, if this happens make sure your battery is fully charged. If the battery doesn’t have enough juice, it will cause all sorts of problems.

At this point we have mechanical build of robot completed and robot electronic hardware components connected. Also, we have IMU and Dynamixel tested and calibrated. We are still not done with the testing of all individual hardware components but it will be a lot easier after we do some of the software configuration on host computer and RPi.

In the next article we will jump into the software installation, configuration and some more hardware testing of RPLidar and Joystick controller before we can get the robot up and running.

--

--

Responses (1)