Getting Started with Actuator Control over UAVCAN/DroneCAN
This example shows you how to use the PX4 Actuator Write
block to write actuator values over UAVCAN/DroneCAN interface.
Introduction
UAV Toolbox Support Package for PX4® Autopilots enables you to write actuator values to the Motor ESCs and Servos connected over PWM or UAVCAN/DroneCAN interface.
In this example, you will learn how to create and run a Simulink® model to write actuator values for controlling Motors and Servos.
Prerequisites
If you are new to Simulink, watch the Simulink Quick Start video.
Perform the initial Setup and Configuration of the support package using Hardware Setup screens.
Required Hardware
To run this example, you will need the following hardware:
Supported PX4 Autopilot
Micro USB type-B cable
Model
Open the px4ActuatorWrite model.
Assuming you are designing a quadcopter and aim to send actuator values to the four motors, this model utilizes the PX4 Actuator Write block to transmit actuator values to the four motors. Passing a true value to the "Arm" input, arms the actuators. In this model, a single value of 0.2
is sent to all four motors to provide 20%
thrust.
If your motors are connected and powered, ensure the propellers are removed for safety.
The ActuatorOutputs uORB
topic is used to read the actuator values back into Simulink and display them.
Note: ActuatorOutputs will only reflect the values for PWM Main channels. For PWM AUX and UAVCAN, ActuatorOutputs will not show the actuator values that you are writing.
Writing Actuator Values Over UAVCAN/DroneCAN
In this section, you will explore how to configure and write actuator values over the UAVCAN/DroneCAN Interface.
Step 1: Configure the Actuators from QGroundControl
Perform these steps to configure QGroundControl (QGC) for UAVCAN/DroneCAN.
Note: MAVLink needs to be enabled over USB (/dev/ttyACM0) for QGC connectivity. For more information, see Enabling MAVLink in PX4 Over USB.
1. Connect the PX4 Autopilot to your computer and wait until QGroundControl establishes a connection with the hardware.
2. For this example, as we are focusing on a quadcopter, select Generic Quadcopter as the airframe in the Vehicle Setup -> Airframe tab of QGC. Reboot the hardware for this change to take effect.
3. After selecting the airframe, go to the Actuator tab (Vehicle Setup -> Actuators) and choose Sensor and Actuators (ESCs) Automatic Config option. Reboot the hardware again for this change to take effect.
4. Assign the four motors to the first 4
UAVCAN ESC channels respectively. With this configuration, the actuator values will now be sent over the UAVCAN ESCs.
5. Keep the other UAVCAN ESCs, Servos, PWM Main channels, and PWM AUX channels as Disabled.
After completing these steps and ensuring your configurations are correct, you can close or disconnect from QGroundControl. If prompted, restart the QGroundControl.
Step2: Configure Model for Supported Pixhawk Hardware
In this section, you will configure the model for the supported Pixhawk hardware.
This example is configured to use Pixhawk 6x hardware. If you are using a different supported Pixhawk hardware, perform these steps. If you are using the Pixhawk 6x hardware, only points 3 and 4 are necessary.
1. In your Simulink model, Go to Modeling > Model Settings to open the Configuration Parameters dialog box.
2. Click Hardware Implementation pane, and select the required Pixhawk hardware from the Hardware board list.
3. Navigate to Target hardware resources > MAVLink and select Enable MAVLink on /dev/ttyACM0. For more information, see Enabling MAVLink in PX4 Over USB.
4. Click Apply and OK.
Step 3: Run the Model and Validate the Actuator Values
1. Click Build, Deploy & Start from Deploy section of Hardware tab in the Simulink Toolstrip.
The code will be generated for the Controller model and the same will be deployed to the Pixhawk board (Pixhawk 6x in this example).
2. Start QGC and wait for it to get connected. Go to Analyze Tools and navigate to MAVLink Console.
3. Enter the uavcan status
command in the console.
nsh > uavcan status
This action will display the actuator values being updated from Simulink. Since the actuator value of 0.2
was written, you should observe the value 1639
, which represents 20%
of the maximum value.
If the UAVCAN/DroneCAN ESC is connected to the CAN bus and has been correctly configured, these values should also be transmitted to the corresponding ESC. For more information on configuring UAVCAN/DroneCAN ESCs, see PX4 documentation.