mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 08:13:34 +08:00
uORB::Publication simplify and cleanup
- base class is now template - drop linked list - virtualization no longer required
This commit is contained in:
@@ -93,14 +93,7 @@ GpsFailure::on_active()
|
||||
q.copyTo(att_sp.q_d);
|
||||
att_sp.q_d_valid = true;
|
||||
|
||||
if (_att_sp_pub != nullptr) {
|
||||
/* publish att sp*/
|
||||
orb_publish(ORB_ID(vehicle_attitude_setpoint), _att_sp_pub, &att_sp);
|
||||
|
||||
} else {
|
||||
/* advertise and publish */
|
||||
_att_sp_pub = orb_advertise(ORB_ID(vehicle_attitude_setpoint), &att_sp);
|
||||
}
|
||||
_att_sp_pub.publish(att_sp);
|
||||
|
||||
/* Measure time */
|
||||
if ((_param_nav_gpsf_lt.get() > FLT_EPSILON) &&
|
||||
|
||||
@@ -43,6 +43,9 @@
|
||||
|
||||
#include "mission_block.h"
|
||||
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/vehicle_attitude_setpoint.h>
|
||||
|
||||
class Navigator;
|
||||
|
||||
class GpsFailure : public MissionBlock, public ModuleParams
|
||||
@@ -72,7 +75,7 @@ private:
|
||||
|
||||
hrt_abstime _timestamp_activation{0}; //*< timestamp when this mode was activated */
|
||||
|
||||
orb_advert_t _att_sp_pub{nullptr};
|
||||
uORB::Publication<vehicle_attitude_setpoint_s> _att_sp_pub{ORB_ID(vehicle_attitude_setpoint)};
|
||||
|
||||
/**
|
||||
* Set the GPSF item
|
||||
|
||||
@@ -440,12 +440,7 @@ MissionBlock::issue_command(const mission_item_s &item)
|
||||
// params[1] new value for selected actuator in ms 900...2000
|
||||
actuators.control[(int)item.params[0]] = 1.0f / 2000 * -item.params[1];
|
||||
|
||||
if (_actuator_pub != nullptr) {
|
||||
orb_publish(ORB_ID(actuator_controls_2), _actuator_pub, &actuators);
|
||||
|
||||
} else {
|
||||
_actuator_pub = orb_advertise(ORB_ID(actuator_controls_2), &actuators);
|
||||
}
|
||||
_actuator_pub.publish(actuators);
|
||||
|
||||
} else {
|
||||
_action_start = hrt_absolute_time();
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <systemlib/mavlink_log.h>
|
||||
#include <uORB/Publication.hpp>
|
||||
#include <uORB/topics/actuator_controls.h>
|
||||
#include <uORB/topics/mission.h>
|
||||
#include <uORB/topics/position_setpoint_triplet.h>
|
||||
#include <uORB/topics/vehicle_command.h>
|
||||
@@ -132,5 +134,5 @@ protected:
|
||||
hrt_abstime _action_start{0};
|
||||
hrt_abstime _time_wp_reached{0};
|
||||
|
||||
orb_advert_t _actuator_pub{nullptr};
|
||||
uORB::Publication<actuator_controls_s> _actuator_pub{ORB_ID(actuator_controls_2)};
|
||||
};
|
||||
|
||||
@@ -117,11 +117,6 @@ public:
|
||||
*/
|
||||
void load_fence_from_file(const char *filename);
|
||||
|
||||
/**
|
||||
* Publish the geofence result
|
||||
*/
|
||||
void publish_geofence_result();
|
||||
|
||||
void publish_vehicle_cmd(vehicle_command_s *vcmd);
|
||||
|
||||
/**
|
||||
@@ -329,13 +324,14 @@ private:
|
||||
|
||||
uORB::SubscriptionData<position_controller_status_s> _position_controller_status_sub{ORB_ID(position_controller_status)};
|
||||
|
||||
orb_advert_t _geofence_result_pub{nullptr};
|
||||
uORB::Publication<geofence_result_s> _geofence_result_pub{ORB_ID(geofence_result)};
|
||||
uORB::Publication<mission_result_s> _mission_result_pub{ORB_ID(mission_result)};
|
||||
uORB::Publication<position_setpoint_triplet_s> _pos_sp_triplet_pub{ORB_ID(position_setpoint_triplet)};
|
||||
uORB::Publication<vehicle_roi_s> _vehicle_roi_pub{ORB_ID(vehicle_roi)};
|
||||
|
||||
orb_advert_t _mavlink_log_pub{nullptr}; /**< the uORB advert to send messages over mavlink */
|
||||
orb_advert_t _mission_result_pub{nullptr};
|
||||
orb_advert_t _pos_sp_triplet_pub{nullptr};
|
||||
orb_advert_t _vehicle_cmd_ack_pub{nullptr};
|
||||
orb_advert_t _vehicle_cmd_pub{nullptr};
|
||||
orb_advert_t _vehicle_roi_pub{nullptr};
|
||||
|
||||
// Subscriptions
|
||||
home_position_s _home_pos{}; /**< home position for RTL */
|
||||
|
||||
@@ -427,12 +427,7 @@ Navigator::run()
|
||||
|
||||
_vroi.timestamp = hrt_absolute_time();
|
||||
|
||||
if (_vehicle_roi_pub != nullptr) {
|
||||
orb_publish(ORB_ID(vehicle_roi), _vehicle_roi_pub, &_vroi);
|
||||
|
||||
} else {
|
||||
_vehicle_roi_pub = orb_advertise(ORB_ID(vehicle_roi), &_vroi);
|
||||
}
|
||||
_vehicle_roi_pub.publish(_vroi);
|
||||
|
||||
publish_vehicle_command_ack(cmd, vehicle_command_s::VEHICLE_CMD_RESULT_ACCEPTED);
|
||||
}
|
||||
@@ -473,7 +468,7 @@ Navigator::run()
|
||||
_geofence_violation_warning_sent = false;
|
||||
}
|
||||
|
||||
publish_geofence_result();
|
||||
_geofence_result_pub.publish(_geofence_result);
|
||||
}
|
||||
|
||||
/* Do stuff according to navigation state set by commander */
|
||||
@@ -746,12 +741,7 @@ Navigator::publish_position_setpoint_triplet()
|
||||
_pos_sp_triplet.timestamp = hrt_absolute_time();
|
||||
|
||||
/* lazily publish the position setpoint triplet only once available */
|
||||
if (_pos_sp_triplet_pub != nullptr) {
|
||||
orb_publish(ORB_ID(position_setpoint_triplet), _pos_sp_triplet_pub, &_pos_sp_triplet);
|
||||
|
||||
} else {
|
||||
_pos_sp_triplet_pub = orb_advertise(ORB_ID(position_setpoint_triplet), &_pos_sp_triplet);
|
||||
}
|
||||
_pos_sp_triplet_pub.publish(_pos_sp_triplet);
|
||||
|
||||
_pos_sp_triplet_updated = false;
|
||||
}
|
||||
@@ -1115,14 +1105,7 @@ Navigator::publish_mission_result()
|
||||
_mission_result.timestamp = hrt_absolute_time();
|
||||
|
||||
/* lazily publish the mission result only once available */
|
||||
if (_mission_result_pub != nullptr) {
|
||||
/* publish mission result */
|
||||
orb_publish(ORB_ID(mission_result), _mission_result_pub, &_mission_result);
|
||||
|
||||
} else {
|
||||
/* advertise and publish */
|
||||
_mission_result_pub = orb_advertise(ORB_ID(mission_result), &_mission_result);
|
||||
}
|
||||
_mission_result_pub.publish(_mission_result);
|
||||
|
||||
/* reset some of the flags */
|
||||
_mission_result.item_do_jump_changed = false;
|
||||
@@ -1132,20 +1115,6 @@ Navigator::publish_mission_result()
|
||||
_mission_result_updated = false;
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::publish_geofence_result()
|
||||
{
|
||||
/* lazily publish the geofence result only once available */
|
||||
if (_geofence_result_pub != nullptr) {
|
||||
/* publish mission result */
|
||||
orb_publish(ORB_ID(geofence_result), _geofence_result_pub, &_geofence_result);
|
||||
|
||||
} else {
|
||||
/* advertise and publish */
|
||||
_geofence_result_pub = orb_advertise(ORB_ID(geofence_result), &_geofence_result);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Navigator::set_mission_failure(const char *reason)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user