In Lab 8 we have learned how to attach the Bluetooth module to our robot car and the theory behind the UART communication. In this lab we will do something really fun that is remotely control the robot car with an Android or PC controller as you wish. Make sure you understand how UART works and have done the set up in previous labs before you get in this lab.
PartsWe will continue using all the parts in lab 8.
ControllerWe have two versions of controller, Android app and PC controller, both are easy to use and straightforward. With the Android app you can control the car with virtual joysticks. If you are using the PC controller, simply follow the instruction to connect the Bluetooth module and use 'WASD' keys or direction keys to control the movement.
Our controller supports multi-key input, which means you can control the car moving forward/backward while turning at the same time. For example, you can let the car go 'left-forward' by sliding the two joysticks (Android) or pressing 'WA' (PC) at the same time. You will see that in our demo video.
Control LogicControl logic is the first thing to start this lab. When the user play with the controller either in Android or PC, the data will be sent to webFPGA through Bluetooth module and be converted to control signal for next step movement of the robot car.
Same as the receiver test in lab 8, our control signal will have 8 data bits. Most significant bit (Bit 7) will always be 1 while we have control signal in, bit 6 will select the motor (0 for left, 1 for right), bit 5 will indicate the motor direction (0 for forward, 1 for backward), bit 4-0 will control the motor speed. The actual speed (in deg/sec) is calculated by multiplying the "speed data bits" by 32. This command format supports speed within range [0, 1023deg/sec]. Speed over this range will cause malfunction in robot control (mainly the direction control).
Format:
| bit 7 | bit 6 | bit 5 | bits 4-0 |
|-------|----------------|----------------------|---------------|
| 1 | 0-left,1-right | 0-forward,1-backward | Speed Control |
Examples:
0 1 0 11010 -- Not a command, stop both motors
1 0 0 01001 -- left motor, forward, 288 deg/sec
1 1 1 10110 -- right motor, backward, 704 deg/sec
The task of the control module is to convert commands in this format to control signals of the corresponding motors.
Aside from the main control logic, we implemented two more useful features:
- Sleep after 3 seconds if no data coming, any new data sent in will wake the robot car
To achieve the 3 seconds sleep function, we set up a counter in our Rx_wrapper module. Counter will count for 3 seconds if no data coming from user, and the car will stop current movement and wait for coming up signals to wake it up. The counter resets upon receiving data.
- Wall detection using bumpers in front of the car. Robot will not be able to move forward when it hits a 'wall' even if the user send forward command, but it still can move backward.
Wall detection is done by using the signal coming from the bumpers in front of the car. The 'wall' can be any obstacles that reaches the height of the bumpers. In detail, we have six bumpers facing different directions. When any of the bumpers is triggered, it will send a signal to the car to make it stop moving forward.
TestHardware
We use the same pin setup as lab 8, please follow that for your pin setup.
Our remote-control module receives 8-bit control signal and convert it into motor selection, direction selection and motor speed. Control signal format has been explained above in control logic. Verilog module will not be illustrated here but you can explore that in detail on GitHub.
Software
Software development is beyond the scope of this lab so we will not discuss how the applications are built here. That being said, the source code is included in the GitHub repository so feel free to explore by yourself if you are interested.
Instruction of Bluetooth connection has been demoed in lab 8. If you are using Android controller, please refer to that instruction and connect your device. After the device is connected, switch to the "Controller" tab and play with the virtual joysticks. A detail demo video below will also show the steps for it.
For PC users, the controller is straightforward to use. Just run the script and follow the instructions and you will be good to go!
Android Demo
PC Demo
EndingNow you have finished this lab. Since this is the last lab of the project, you have also finished the project and is now ready to explore more with what you have learned here, congratulations!
Comments