Switching a Robotic System between Autonomous and Manual Mode
This example shows how to switch a Robotic System between autonomous and manual mode when deploying an executable from a MATLAB function or Simulink model to 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.
Four 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 function 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. Build and run the executable using the following script
This script will generate an executable out of the function RemoteDesktopSwitchHostDsp.
This executable should be run outside of MATLAB so that it does not interfere with the blocking Simulink model.
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.