Receive Data from an RC Receiver
This example shows how to receive data from an RC Receiver attached to an Arduino.
One common question when working with different robots is how to use an R/C controller to control it.
Standard robotics has the R/C receiver send a servo-style pwm signal directly to the servo motors or the motor controller as indicated by the diagram below with Method 1.
Many roboticists look to change this relationship by placing a microcontroller in between the R/C receiver and the motors as shown with Method 2. This allows the user to create fly/drive-by-wire programs on the microcontroller where you can for example, design traction control algorithms.
You could even take it one step farther by using one of the channels on the R/C Controller to switch the code between different operating modes i.e. Manual R/C Control vs. Automated.
This example will show how to program an Arduino Mega 2560 using Simulink to receive R/C signals.
The output of the R/C receiver consists of 4 servo style signals. Servo signals are pulses with a width of about 1-2 ms and a period of about 20 ms. The length of 1 ms is the minimum pulse, 2 ms is the maximum pulse and 1.5 ms is the neutral pulse. There are two types of servo motors, continuous servos and position servos. For a continuous servo, the length of the pulse corresponds to the speed of rotation. For a position servo, the length of the pulse corresponds to the angular position of the servo. When controlling aircraft with an R/C remote, the receiver is connected to position servos.
When a neutral pulse is sent to a continuous servo the servo stops. When a maximum pulse is sent to the continuous servo, the servo moves full speed in one direction i.e. clockwise at 180 °/s. When the minimum pulse is sent the continuous servo moves full speed in the opposite direction i.e. counterclockwise at 180 °/s . Any value in between these ranges corresponds to a particular speed.
Similarly, when a neutral pulse is sent to a position servo, the servo moves to a neutral position. When a maximum pulse is sent to a position servo, the servo moves to some angle in one direction i.e. clockwise to +90°. When the minimum pulse is sent the position servo moves to some angle in the opposite direction i.e. counterclockwise to -90°. Any value in between these ranges corresponds to a particular angle.
We recommend completing Getting Started with Arduino Mega 2560 Hardware.
To run this example you will need the following hardware:
- Arduino Mega 2560
- USB Cable
- Generic R/C controller and receiver
- Connect pins 2, 3, 18, and 19 to the 4 channels on the R/C receiver.
- Supply power and ground to the R/C receiver. I connected the power (5V) and ground (GND) pins on the Arduino directly to the R/C Receiver.
1. Open the following model:
2. Click the “Run” button to enter external mode.
This driver block attaches externally triggered interrupts to the pins that are specified in the block. These interrupts are bidirectionally triggered (i.e. when the input goes from high to low or low to high). The code in this block uses the two triggers to measure the length of the input pulse. As the joystick moves in the up or right direction, the pulse gets larger, and the code returns a larger value.
For more information on this, feel free to check out the following blog, which describes the c implementation of the algorithm in the Arduino IDE: