Actuator Control Using Write Thrust & Torque Blocks for PX4 Autopilots
This example shows how to use the PX4 Write Thrust & Torque block to command the actuators.
UAV Toolbox Support Package for PX4 Autopilots includes a Simulink blocks for for writing thrust and torque setpoint value. In this example, you generate code for a Simulink model and deploy it to a PX4 Cube Orange, and thus spin the motors at 20% throttle.
Prerequisites
If you are new to Simulink, watch the Simulink Quick Start video.
For safety purpose, remove propellers from Cube Orange drone.
Perform the initial Setup and Configuration of the support package using Hardware Setup screens. Select
PX4 Cube Orange
as the PX4 Autopilot board in Hardware Setup screens.
Perform sensor calibration and radio setup.
Required Hardware
To run this example, you will need the following hardware:
Cube Orange
Micro USB (Universal Serial Bus) type-B cable
Required Third-Party Software
Recommended: QGC version 4.3.0
Model
To get started, open px4demo_actuatorControl model.
Configure and Run the Model
In this task, you will configure and run the pre-defined Simulink model (px4demo_actuatorControl) and deploy it to the PX4 Cube Orange board.
1. In the Modeling tab, click Model Settings.
2. In the Configuration Parameters dialog box, navigate to the Hardware Implementation pane.
3. If you are using a hardware board other than PX4 Cube Orange, then select appropriate hardware board.
4. In the Simulation tab, set the Stop Time to inf.
5. Connect the USB cable from the Cube Orange to the host computer.
6. On the Hardware tab, in the Mode section, select Run on board and then click Build, Deploy & Start. The model is deployed to the PX4 hardware board.
This deploys the controller code on the Cube Orange and launches the QGroundControl (QGC).
Note: If you are using Ubuntu, QGC might not launch automatically. To launch QGC, open Terminal and go to the location where QGC is downloaded and run the following command:
./QGroundControl.AppImage
Configure QGroundControl and Fly Cube Orange
1. In the QGC, select Airframe.
Navigate to Setup > Airframes.
Select Generic Standard Plane. Click Apply and Restart on top-right of the Airframe Setup page.
Restart QGC to allow it to connect to the board and apply the new settings.
2. Navigate to Setup > Safety section.
Select HITL and SIH disabled from the HITL Enabled list.
3. Navigate to Actuators tab and identify and assign the main motors.
4. In General tab for AutoConnect options, select Pixhawk and UDP.
5. Click Comm Links and configure the communication links. For more information see Configuring QGC for Vehicle Visualization Without a Display.
6. Select Virtual Joystick.
In the General tab, from Fly View of the settings menu, select Virtual Joystick option.
7. Set the following parameters.
Disable the parameter COM_ARM_SWISBTN for arming/disarming triggers on switch transition.
Enable the parameter MAN_ARM_GESTURE for arm stick gesture.
Disable the parameter COM_ARM_HFLT_CHK for FMU SD card hardfault detection check.
8. Restart the QGC to apply the changes.
Change the flight mode to Manual in the QGC.
Drag the left joystick to the bottom-right corner for a couple of seconds to force arm the UAV.
All four motors now spins at 20% throttle.
Validate Actuator Values
1. In the QGC, go to Analyze Tools and navigate to MAVLink Console.
2. Enter the px4 io status command in the console.
nsh > px4io status
This action updates the actuator values displayed from Simulink. Since the actuator value of 0.2 was written, observe the value updated to 1260.
This value is obtained using a minimum value of 1100 and a maximum value of 1960. To find the updated value, multiply 0.2 by the difference between the maximum and minimum values (which is 800) and then add the result to the minimum value of 1100. Therefore, you calculate the updated value as ((0.2 \times 800) + 1100 = 1260).