Hi!
Currently I am trying to switch the state of the px4 to offboard. I do so by activating the CommanderState receive: true in the uorb_rtps_message_idl.yaml. Then I use this script to publish the message over fastRTPS:
auto timer_callback = [this]()->void { if(i_setpoint_ < 100) { auto position_setpoint = px4_msgs::msg::PositionSetpoint(); position_setpoint.timestamp = timestamp_; position_setpoint.x = 0.0; position_setpoint.y = 0.0; position_setpoint.z = 0.0; std::cout << "setpoint iteration: " << i_setpoint_ << std::endl; this->setpoint_publisher_->publish(position_setpoint); i_setpoint_++; } else { if (!switched_to_offboard) { auto commander_state = px4_msgs::msg::CommanderState(); commander_state.timestamp = timestamp_; commander_state.main_state = px4_msgs::msg::CommanderState::MAIN_STATE_OFFBOARD; this->commander_state_publisher_->publish(commander_state); std::cout << "Switched to offboard control mode." << std::endl; switched_to_offboard = true; } else { std::cout << "nothing to do" << std::endl; } } };
However the mavlink shell (sometimes) gives me the following warning:
nsh> WARN [micrortps_client] Unexpected topic ID
If I can listen to the message through ros2 topic echo, I see:
$ ros2 topic echo /CommanderState_PubSubTopic
timestamp: 0
main_state: 7
If I use the listener in the mavlink shell I get the following result:
nsh> listener commander_state
TOPIC: commander_state
commander_state_s
timestamp: 1104099513 (0.225175 seconds ago)
main_state: 0
Could somebody please elaborate why the topic ID is unexpected (this doesn’t always happen, sometimes it doesn’t give any feedback at all) and why it is not reacting? Since MAVROS uses the same topic (commander_state for mode switching and vehicle_command for arming) I am unsure why the micrortps_client is rejecting the input of this topic. I have the same problem for arming the px4.
Cheers!