matlab publish to ros2 wrong

15 vues (au cours des 30 derniers jours)
雨蒙
雨蒙 le 4 Déc 2025 à 12:32
Réponse apportée : 雨蒙 le 7 Déc 2025 à 6:12
i found that when i use the code or simulink model to send /fmu/in/vehicle_command. and then i get the response
response:
timestamp: 1764851141943341
param1: 1.0
param2: 6.0
param3: 0.0
param4: 0.0
param5: 0.0
param6: 0.0
param7: 0.0
command: 176
target_system: 1
target_component: 1
source_system: 1
source_component: 256
confirmation: 0
from_external: false
code:
node = ros2node("/control_node");
% General information about the UAV system
controlModePub = ros2publisher(node,"fmu/in/offboard_control_mode","px4_msgs/OffboardControlMode");
statusSub = ros2subscriber(node,"/fmu/out/vehicle_status","px4_msgs/VehicleStatus","Reliability","besteffort");
timeSub = ros2subscriber(node,"/fmu/out/timesync_status","px4_msgs/TimesyncStatus","Reliability","besteffort");
% Sensor and control communication
odomSub = ros2subscriber(node,"/fmu/out/vehicle_odometry","px4_msgs/VehicleOdometry","Reliability","besteffort");
setpointPub = ros2publisher(node,"fmu/in/trajectory_setpoint","px4_msgs/TrajectorySetpoint");
cmdPub = ros2publisher(node,"/fmu/in/vehicle_command","px4_msgs/VehicleCommand");
cmdMsg = ros2message(cmdPub);
cmdMsg.command = uint32(cmdMsg.VEHICLE_CMD_DO_SET_MODE);
cmdMsg.param1 = single(1);
cmdMsg.param2 = single(6);
publishVehicleCommand(timeSub,cmdPub,cmdMsg)
function publishVehicleCommand(timeSub,cmdPub,cmdMsg)
cmdMsg.timestamp = timeSub.LatestMessage.timestamp;
cmdMsg.target_system = uint8(1);
cmdMsg.target_component = uint8(1);
cmdMsg.source_system = uint8(1);
cmdMsg.source_component = uint8(1);
cmdMsg.from_external = true;
send(cmdPub,cmdMsg)
end
the from_external and source_component is different, and i don't know why.
  1 commentaire
雨蒙
雨蒙 le 5 Déc 2025 à 3:19
may be it is not a question, PX4 would chagne it auto.
however, ifound the reason why i can't control my UAV stability.
i set the param in simulink like this.
when i see the result in wsl2, i found the frequency is 1HZ as follow:
The PX4 request >2HZ, so it result the question .
and i don't know how to deal it.

Connectez-vous pour commenter.

Réponses (1)

雨蒙
雨蒙 le 7 Déc 2025 à 6:12
And I have another question: when I control the UAV in Offboard mode using Simulink, I get the following error:
I followed the suggested solution from this post—increasing the COM_OF_LOSS_T parameter value:
It seems to help!
However, I’m still not sure what’s causing the issue. It looks like there might be a problem with the publishing rate or timing in my Simulink setup.

Tags

Produits


Version

R2025b

Community Treasure Hunt

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

Start Hunting!