Table of contents
Purpose of the program
Description of the program
Information exchange protocol
Purpose of the program
The software is intended to be loaded into the microcontroller hardware Selfie Bot Hardware Base, built on the base board Arduino Nano, comprising a microcontroller Atmel ATmega168 or ATmega328.
This software makes it possible to connect to the device SelfieBot and control the connected servos.
Description of the program
After starting the device initialization is done: run the setup function commands – Initialization pins, UART configuration interface, setting the servo to the initial position. During initialization, the LED lights technology (Arduino Nano to the boards are usually marked with the letter L), which goes out on successful initialization after 1 second.
After initialization, the loop function starts running in an infinite loop – going survey software interface module _Interf_UART to transfer results to the software modules and _Control_Servo1 _Control_Servo2.
_Interf_UART Software module provides a UART reception for the team. In the received stream for UART is a search and identification of a data packet in accordance with a protocol for information exchange. In the case of command detection occurs issuance of the control byte. Work with internal UART provides a library of Serial.
Since the protocol is fixed, then, to the stability of the failure, the module receives each new byte, which came on the UART, and compares it with the expected, in the case of coincidence of the structure of the package is considered to be the last byte of the command and issued. If the bytes do not expect the reception of reset. In the event of failure of the whole exchange, this ensures the correct reception of the next packet (following the flawed) without re-initialization reception timeout circuitry that determines the end of data reception.
Software modules and Control_Servo1 _Control_Servo2 ensure alignment to the servos using the Servo Library command. Upon receipt of the control byte of the interface module takes place identification byte management and development of signals to permit rotation of the actuator in the desired direction. After a certain time (Time_rotate) stops rotation, if not received any other team identified.
Information exchange protocol
Interaction with external devices takes place via UART at 9600 baud.
The data packet consists of five bytes. The first four bytes represent a prefix and are constant in each package. The fifth byte is a byte command.
The structure of the package
№ Byte | 1 | 2 | 3 | 4 | 5 |
Command symbol | c | o | m | = | |
Command byte | 0x63 | 0x6F | 0x36 | 0x3D |
Table 4. Management Team (fifth byte in the packet)
Command symbol | Command byte | Command |
W | 0x57 | Rotation of a vertical servo to the up |
S | 0x53 | Rotation of a vertical servo to the down |
A | 0x41 | Rotate of a horizontal servo to the left |
D | 0x44 | Rotate of a horizontal servo to the right |
x | 0x78 | Stop of any movements |
R | 0x52 | Return servos to the starting point |