matlab publish to ros2 wrong
Mostrar comentarios más antiguos
when i follow the article https://ww2.mathworks.cn/help/ros/ug/control-a-simulated-uav-using-ros2-and-px4-bridge.html
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 comentario
雨蒙
el 5 de Dic. de 2025
Respuestas (1)
雨蒙
el 7 de Dic. de 2025
0 votos
Categorías
Más información sobre Publishers and Subscribers en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


