Clear Filters
Clear Filters

How can I read the rotor velocities in the PX4 read block in Simulink?

6 views (last 30 days)
I'm developing an open loop system for a quadrotor in Simulink using PX4 toolbox, simulating on jMAVsim. I'm injecting the rotor velocities and I have to read and plot the vehicle odometry(positions,velocities,euler angles etc...). I'm doing this thanks to the PX4 read block on the vehicle_odometry message that contains all this info, but I do not know how to read the rotor velocities in order to check if they are equals to the injected ones. How can I do? Which message do I have to use?
Arun Mathamkode
Arun Mathamkode on 23 May 2023
Can you please clarify how are you injecting the rotor velocities ? Are you using any uORB write blocks?
Salvatore Matteo Mennea
Salvatore Matteo Mennea on 23 May 2023
Edited: Salvatore Matteo Mennea on 23 May 2023
I'm mapping the rotor velocities through a matlab function into a Ton(ms) and then I used the mapped velocity into the PWM output block in PX4 Toolbox. As it's written in a Mathworks PX4 Demo ( ):
"The PX4 PWM Output block expects values of uint16 datatype for rotational speeds, and each input can take a value between 1000 and 2000. A Gain block with Gain set to 1000 facilitates these requirements related to a compatible data type and scaling."
When this block has as input 900, the drone is disarmed. So I mapped linearly the rotor velocities knowing that at 900 the velocities is zero and at 2000 we have the max rotor velocity which is 1100 rad/s. So I used this function CH1=0.001*omega1+0.9, for the 4 rotors. I used the 1000 gain to scale the output and to convert the data into uint16 which the PWM block requires.
Then I want to read the system states and rotor velocities, so I did this:
The PX4 read block for odometry works perfectly, I'm able to read the open loop system states, but the uORB msg with rpm does not work(it says the rotor velocities are zero which is impossible becouse the drone takes off).I have also used the esc_report.msg but I have the same issue and there's no vehicle_motor_speed message type as the answer below suggested to use. How can I read the rotor velocities of the quadcopter in open loop?

Sign in to comment.

Accepted Answer

Shaik on 16 May 2023
Hi Salvatore,
To read the rotor velocities of a quadrotor in PX4 using the PX4 toolbox in Simulink, you can use the vehicle_motor_speed message. This message provides information about the motor speeds or rotor velocities of the quadrotor.
Here's how you can read and plot the rotor velocities using the PX4 toolbox:
  1. Add a PX4 read block to your Simulink model.
  2. Configure the PX4 read block to use the vehicle_motor_speed message type.
  3. Connect the output of the PX4 read block to a MATLAB Function block or a Scope block.
  4. Inside the MATLAB Function block, you can access the rotor velocities by using the output signal of the PX4 read block.
  5. To plot the rotor velocities, you can use the MATLAB plotting functions, such as plot or stairs.
Here's an example of how the Simulink model could be structured:
| PX4 Read Block |
| vehicle_motor_speed
| MATLAB Func |
| rotor_velocities
| Scope Block |
function rotorVelocities = fcn(vehicle_motor_speed)
% Read rotor velocities
rotorVelocities = vehicle_motor_speed.RPMs;

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!