POSCTL requires local_position.timestamp, local_position.xy_valid and local_eph_good, all three variables in commander, to be valid.
Local_position.timestamp and local_position.xy_valid come from topic vehicle_local_position, and local_eph_good indicates the gps horizontal accuracy.
Time stamp is valid when current px4 time t that t < timestamp + timeout and t > timeout are valid.
Time stamp comes from mavlink message #32. Since ROS and PX4 have their own clock time, time stamp data needs to be synchronized before being sent to PX4.
The above diagram shows time stamp synchronization built between ROS and PX4. A publisher in roscopter was built to get px4 time from mavlink message #30, and publish the time to roscopter. In roscopter, processing time is added to px4 time, and finally the corrected time is sent back to PX4 with local position through mavlink message #32.
The other two variables were also modified in last week. Finally, flight mode switching was achieved.
Abused mavlink message #89
Mc_position_control requires data from topic vehicle_local_position more than mavlink message #32 could provide, and those data are all calculated in position_estimator_inav. As a result, the idea of disabling position_estimator_inav was given up. Instead, data from pose_estimator would be passed into position_estimator_inav.
To avoid overriding topic vehicle_local_position (which is correspond to #32), mavlink message #89 was abused to send local position data from roscopter to PX4 instead of #32.
This data from last week shows that the local position data were sent to PX4 with #89. The left window shows that the data were sent in roscopter, and the right front window shows that PX4 display the received data with a display subscriber. However, x was 0 instead of 1, y was 1 instead of 2, and etc.. It was due to type casting error in decoding.
This week, type casting error was fixed. Finally, it is sure that #89 can be sent to PX4.