Switching a Robotic System between Autonomous and Manual Mode
This example shows how to switch a Robotic System between autonomous and manual mode when running a MATLAB Function or Simulink Model directly on a desktop computer.
An RC Receiver outputs a servo pulse with a length ranging from 1000 to 2000 microseconds. This pulse is received by the Arduino through a pin which supports interrupts. The interrupt measures the width of this pulse and outputs it from the Arduino RC Receive Simulink block.
For a 4 channel RC receiver, we have four output signals to work with. Two of these signals can be used to control the linear and angular velocity of the vehicle. One of the remaining two can be used to toggle the vehicle between autonomous and manual mode.
Let's use channel 3. If channel 3's output is below 1500 microseconds, we can set the vehicle to run in autonomous mode. As a result, the actuation commands sent by the desktop computer will be passed on by the Arduino to control the motors. The signals from the first two RC channels will be ignored.
If channel 3's output is above 1500 microseconds, we can set the vehicle to run in manual mode. As a result, the output of the first two channels will be used directly by the Arduino to control the motors. All received communication from the desktop computer will be ignored.
The following Simulink model can be deployed to an Arduino. This model receives data from the RC receiver, and uses the 3rd channel to determine if the motor commands should be forwarded from the RC receiver or the desktop computer.
1. Run the model in external mode.
The following MATLAB script can be run on the desktop computer. This script will act as the autonomous algorithm running on the computer. It will transmit a motor command of [-90, 90] to the Arduino every 0.1 seconds.
2. Run this script
3. Move the joystick on the RC Receiver corresponding to channel 3 to see the motor command output shift between autonomous and manual mode.
Setting the joystick such that channel 3's value is below 1500 forces the Arduino to pass motor commands from desktop computer. The output should now be [-90; 90];
Moving the joystick such that channel 3's value is above 1500 forces the Arduino to convert the output from the RC Receiver's channel 1 and 2 to motor commands. Move the joysticks corresponding to channel 1 and 2 to see the motor command change.