This project uses an Arty development board to control a two-wheel robot. The robot is built on the Shadow Chassis with motors, wheels, and a wheel encoder kit from SparkFun. The motors are driven by the Pmod DHB1, which is a dual H-bridge. This project has been divided into five milestones, which are detailed below.
The first milestone of this project is to assemble the robot and get it to move forward at full speed. To assemble the chassis, I referenced the text and video assembly guides on the Shadow Chassis' product page on SparkFun during assembly. Because these guides are actually for the SparkFun RedBot, I did not follow the guides exactly and only referenced the portions of the guides for the parts that I had. I also made minor adjustments for parts that were difficult to snap together. For example, the battery pack is meant to held down by a part supplied with the Shadow Chassis, but I used a zip tie instead.
After assembling the chassis, I connected the motors and battery pack to the H-bridge Pmod. The battery pack connects to the screw terminal at J4 to supply power to the motors and the motors receive their supplies through the screw terminals at J5 and J6. Then, I plugged the Pmod into the Arty at the JB connector.
Finally, I programmed the Arty so that toggling the switch SW0 would drive the robot forward at full speed. I did this in an HDL file, motorSwitch.v, which ties SW0 to the enable signals on the H-bridge. After compiling the HDL, I programmed the Arty following step 4 of the Arty Programming Guide. This way, the robot can run untethered from the computer.
The second milestone of this project is to set up a MicroBlaze design that makes SW0 drive the bot forward at half speed. The MicroBlaze design is an extension of the Arty - Getting Started with MicroBlaze tutorial. In addition to adding the USB UART component, I added these components to the system block diagram:
- four switches
- PWM_v2.0 (IP from the Vivado library)
- JB Pmod connector (Pmod Bridge with GPIO interface)
- additional AXI GPIO
- hBridgeConnector (a Verilog module that I wrote)
One of the switches will be used to turn on the motors and drive the bot forward. The pulse-width modulation (PWM) IP will provide a way of controlling the motors' speeds. I have configured the PWM IP to output two signals, one for each motor. The JB connector is where I have connected the H-Bridge Pmod. The additional AXI GPIO IP provides registers that connect to the pins on the JB Pmod connector. The hBridgeConnector module takes the PWM signals and the signals from the AXI GPIO block and connects them to the Pmod Bridge. The connections were made so that the enable pins on the H-Bridge Pmod get the PWM signals and the other H-Bridge pins are connected to GPIO pins on the AXI GPIO block. The source code for this module is available on GitHub.
After the hardware system was set up, I continued on the Getting Started with MicroBlaze tutorial until the point of creating a project in the Xilinx SDK. Here, I created an empty project instead of using the Hello World template. The C files that I created,
, are available on GitHub. There are also files for working with the PWM module in the GitHub repository. These files were taken from the BSP folder in the SDK.
main.c runs a program that turns on the motors at half speed when SW0 is toggled on. The program configures the PWM module to produce a square wave with a 2ms period and a 50% duty cycle. Then, the directions of the motors are set to forward. Finally, the program enters a loop that continually reads SW0 and enables or disables the motors accordingly.
The third milestone is to use feedback from the wheel encoder kit to determine the speed of the robot's wheels. The wheel encoder kit consists of two 8-pole magnetic disks and two Hall effect sensors. The magnetic disks are attached to the motor and the Hall effect sensors are positioned in front of the magnetic disk. The Hall effect sensors produce digital outputs based on the magnetic poles they detect in front of them. Using these output signals from the sensors, I compute the angular speed of the wheels and print the speeds out to a terminal emulator (Tera Term).
To process the signals from the Hall effect sensors, I built a custom IP core following the Creating a Custom IP Core tutorial. This IP core, which I have called EdgeCounter, takes a signal from the sensor, a clock, and a clear signal as inputs. The IP core uses a register to count the number of positive edges on a sensor output signal and another register to count the positive edges of the system's clock. The EdgeCounter also has a clear signal that resets the registers to zero. These two counts are sufficient to compute the average speed of the wheel since the last clear.
In software, I added code to
that uses the registers in the EdgeCounter IP core to compute the wheels' angular speeds. One of the functions,
, reads the registers to get data from the latest time frame. The function called
calculates the wheels' speeds in revolutions per minute (RPM). I have used these two functions in a function called
, which, when called, runs a program that continuously prints the speeds of the wheels in Tera Term. The program formats the text output so that the speeds repeatedly print over themselves in the same part of the screen. When this program is running, you can turn the wheels by hand or turn on the motors at half speed with SW0.
ArtyBot GitHub Repository
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!