basic tank-drive robot control over bluetooth using mbed with the freescale k64f
Drive-style robots using Arduino and Android apps, as shown in RC car for Android Instructure.
Over the past few years, I have used this work as the basis for many robots, such as the walking chassis inspired by Teo Jansen and the full-size remote-controlled wheelchair, and this Instructable will get the basic Arduino code, and use mbed to port it to a micro-controller board based on the flying Carl K64F ARM. org on-line IDE.
This board is very similar to the use of mbed IDE to other mbed-enabled boards.
This example uses
Wingxine 1A controller, a serial portover-
The motor driver code is based on some slightly simpler code that controls more common motor control modules based on the L298N.
Comment out the DBH1 line in main.
Cpp reverts to the default L298N logic.
You need a 4-pin 1-row female 2.
54mm pitch joint for HC-installation
06 turn K64F board. For the DBH-
1x series controller, you will want a 10-12 pin 2-
The header of the parent line, while the L298N module usually uses 6-pin 1-
Head of the line.
This step assumes that you have successfully used mbed on-
Compile, download, and run the IDE lines of your code on your fly Cisco board.
If you haven\'t done so yet, please click on the link in mbed.
Htm files on the K64F board root folder, and/or view instructions for using the flying Carl K64F. Solder a 4-
Connect the pin head of the Bluetooth module to the K64F board and install the Bluetooth module.
From the mbed IDE, select the frdm_serial program modified by Aaron Birenboim and import it.
This is a major modification to the delivered frdm_serial example.
I can\'t get a simple serial number for unknown reasons: getc ()
Calls that work with the Bluetooth module.
This example shows the interrupt-driven ring buffer method adopted throughout the TankDrive robot control program.
When your Bluetooth module is plugged in and the MCU board is powered by the USB of the host, you should see the flash on the Bluetooth module indicating that it is not yet connected to the Bluetooth host.
View the code in main.
Cpp to make sure that the Porter setting of the BT object is set to the baud rate set on the Bluetooth module.
They usually provide serialover-
Bljuadeth module with default rate of 9600 Porter.
This rate can be increased using the AT command, as described in the Instructure of HC-
05 Bluetooth module.
Please note that Arduino is not required to do so.
If you have a USB interfaceto-
Serial converter, can be connected directly to the HC06 class module, enter the AT command.
You can connect to your Bluetooth module with an Android app like BlueTerm.
Open the serial terminal program on the host to communicate with USB-
Serial connection on K64F.
Under chrome, you can use apps like Eagle
Term, or serial monitor on Arduino IDE, or other serial monitor
Be sure to set the baud rate to 115200 or change the mbed code to match the baud rate you want.
You should be able to type text on BlueTerm and see the results on the host serial terminal program.
If you plan to use the CXEM car app in Android RC car control via Bluetooth Instructure, start it.
Enter the MAC address, which should be displayed when you connect to the Bluetooth module from BlueTerm. Enter button-
Control mode and touch button.
If the communication is normal, you should see several Lxxx and Rxxx commands on the host terminal.
Select import from mbed IDE, then select click here to import by URL.
Enter the TankDrive program.
Compile and download images from this code.
After the reset, the program should flash a collection of all primary and free primary colors in order.
The code is running if you see this sequence.
Check the code for int main ()in main.
Cpp to make sure the Bluetooth communication is set to your speed.
Also verify that you have used the same pin called in the global driver constructor near the top of the main. cpp.
If different pins are selected, set their names appropriately in the global constructor of the MotorDrive object in the main preface. cpp.
Many motor control modules with higher power, such as DBH-
1x series with maximum PWM settings.
In the case of DBH-1A this is 98%.
I don\'t know why.
They warned that the transistor would burn out when the 100% duty cycle was running.
Maybe they\'re in N-
The channel mosfet on the high side, if this charge pump runs out, the transistor may not \"turn on\" completely, which will cause it to heat up.
For the sake of safety, I used the PWM pin in the direction input of the motor driver and set the maximum PWM rate of 98% on these lines.
I mainly control the speed through the PWM on the EN pin, but using the 98% duty cycle PWM on the direction pin ensures that I am satisfied with the use of DBH-1x module.
The normal L298N chip does not have this limit.
If you are using the L298N module, please comment out the definition DBH1 line in the preface of main. cpp.
For the L298N drive, the IN1/IN2 signal does not need pins that support PWM.
They can be simple digital I/O pins.
You will also note that the L298N version of the driver is only a monthly input constructor because it does not exist at the moment --
Sensing output provided on most L298N modules.
To test, I connected the motor control signal to the breakout on the breadboard.
Each of these signals is connected to an enlarged logic probe that illuminates an LED.
I am concerned that you may not be able to reliably drive regular 2 v, 20 mA LED from the ARM digital I/O output, especially when they are shared with the 5 v TTL input.
The construction of these amplified logical indicators may be the subject of future teaching.
The one shown is painted.
3 mA m from the digital I/O pin and amplified by a pn Darlington to illuminate the LED from a 5 v power supply.
Since then, I ordered a bag of 2N7000 small-
Signal mosfet for this purpose.
They should be able to switch without the need for a current limiting base resistor and draw almost 0A to drive the light. (
The switch state requires a small amount of current, but the current consumption drops to nA or lower once the transistor state is set)
It\'s good if you don\'t build a test break.
Now that the code has been tested, you should be able to test it directly on the DC motor.
Connect K64F to the motor drive module.
Connect to the Bluetooth module using BlueTerm.
Connect the serial terminal to USB-
View the diagnostics from the serial port on K64F on the host.
Test the timeout of the dead you can change the default 250 to 500 ms thing is more like the 15000 MS initMotorDrive ()
Implementation of Main. cpp.
This will allow you to test from the terminal without a remote control application.
When running the actual Robot, The deadman timeout should be closer to the command application (such as CXEM-
About 100 to 500 ms.
Type A command similar to L255 from a Bluetooth terminal for full-
Forward speed of left Motor. Then L-
Nearly half the time is 99. speed reverse.
You should note that the motor stops briefly under electrical braking and then starts in reverse.
You can do similar things for the right motor with commands like R-255 then R111.
When a command ro or L0 is issued, the motor should stop quickly using an electrical brake.
When the two-way input is low and the capability is high, the electric brake is engaged.
Otherwise, when driving the main speed control, it is done with PWM on the enabling line.
The diagnosis describing all of the above operations can be displayed on the PC-USB terminal.
If you go through the code, more diagnostic reports will be commented out.
Most of these diagnostic programs will have commands like diagnostic sequences. printf(. . . ).
For more diagnostics, you can delete these notes.
I found that too much diagnostic print output causes the MCU to freeze when high output is provided
Rate command stream, such as opne-generated by CXEM-car app.
The use of the remote control app is converted in the instructions for Bluetooth control for Android RC cars.
To sum up: if something doesn\'t work, try connecting with Blueterm or go back to the test serial connection step to make sure the application communicates properly.
If the connection is frozen, try removing the diagnostic print output from the TankDrive firmware.
If all goes well, go back to initMotorDrive ()
The main function in TankDrive.
Cpp, and set the deadman timeout to a reasonable value, such as 250, using row md.
SetCommand timeout (250); .
Download this change and you should be able to command the tank safely-
Robot driving style.
The initial version of this MCU firmware was created by porting an existing Arduino sketch.
Some of the features have been replaced by a more appropriate mbed class, but some of the features of the mbed ARM can be integrated together to make the code more streamlined.
Timers and timeouts may be a better option to implement certain features on the mbed ARM platform, rather than polling techniques for Arduino implementation.
Focus on mbed\'s TankDrive project and learn about the future of this direction.
Flying K64F, 48 MHz clock, 32-
The bit processor is more powerful than this simple demo remote control application.
This app is designed to serve as a start template for more complex robot projects on this platform.