Simulink change PX4 flight mode via MAVROS

조회 수: 10(최근 30일)
Ewan Pugh
Ewan Pugh 2022년 2월 28일
답변: Abhijeet Gadkari 2022년 3월 4일
I am trying to change the flight mode of a PX4 drone via MAVROS in Simulink. When I send the command ,MAVROS gives me the error:
However, when I run the equivalent code in MATLAB it works. Is it something encoding related?
My model creates the flight mode string, casts it to a ASCII array which has a length of 128. I then convert from 2-D to 1-D and assign the mode to the bus.
  댓글 수: 2
Ewan Pugh
Ewan Pugh 2022년 3월 4일
Hi Ankur,
This is the MATLAB code:
client = rossvcclient("/mavros/set_mode","DataFormat","struct");
req = rosmessage(client);
req.CustomMode = 'AUTO.TAKEOFF';
resp = call(client, req)
I managed to get the simulink working for this one case by setting the Maximum length of the CustomMode variable length array to 12 (the same as the number of characters in "AUTO.TAKEOFF") and it works. But I now cannot set different flight modes that aren't 12 characters long.

댓글을 달려면 로그인하십시오.


Abhijeet Gadkari
Abhijeet Gadkari 2022년 3월 4일
Hello Ewan,
You can use the String Length block to output the length of the String Constant and set that value into the CurrentLength field of the mavros_msgs/SetModeRequest message.
This will allow changing the value of String Constant, state, and the CurrentLength field will update with the new value.
You can use the default limits for CustomMode field.
See the example below:




Community Treasure Hunt

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

Start Hunting!

Translated by