mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-30 02:30:35 +08:00
FlightTasks: replace setpoint setters with members
I realized that instead of using the setpoint setters inline in real world tasks everyone started to have its own setpoint member variable and only call the setter in the end for all the privatly generate setpoints. This makes the setter useless and therefore I switched to member setpoints in the architecture. They bring more felxibility which is obviously needed but also less structure which is the price to pay.
This commit is contained in:
@@ -16,13 +16,13 @@ bool FlightTask::initializeSubscriptions(SubscriptionArray &subscription_array)
|
||||
|
||||
bool FlightTask::activate()
|
||||
{
|
||||
_resetSetpoints();
|
||||
_time_stamp_activate = hrt_absolute_time();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlightTask::updateInitialize()
|
||||
{
|
||||
_resetSetpoint();
|
||||
_time_stamp_current = hrt_absolute_time();
|
||||
_time = (_time_stamp_current - _time_stamp_activate) / 1e6f;
|
||||
_deltatime = math::min((_time_stamp_current - _time_stamp_last), _timeout) / 1e6f;
|
||||
@@ -30,6 +30,29 @@ bool FlightTask::updateInitialize()
|
||||
return _evaluateVehiclePosition();
|
||||
}
|
||||
|
||||
const vehicle_local_position_setpoint_s FlightTask::getPositionSetpoint()
|
||||
{
|
||||
/* fill position setpoint message */
|
||||
vehicle_local_position_setpoint_s vehicle_local_position_setpoint;
|
||||
vehicle_local_position_setpoint.timestamp = hrt_absolute_time();
|
||||
_position_setpoint.copyToRaw(&vehicle_local_position_setpoint.x);
|
||||
_velocity_setpoint.copyToRaw(&vehicle_local_position_setpoint.vx);
|
||||
_acceleration_setpoint.copyToRaw(&vehicle_local_position_setpoint.acc_x);
|
||||
_thrust_setpoint.copyTo(vehicle_local_position_setpoint.thrust);
|
||||
vehicle_local_position_setpoint.yaw = _yaw_setpoint;
|
||||
vehicle_local_position_setpoint.yawspeed = _yawspeed_setpoint;
|
||||
return vehicle_local_position_setpoint;
|
||||
}
|
||||
|
||||
void FlightTask::_resetSetpoints()
|
||||
{
|
||||
_position_setpoint *= NAN;
|
||||
_velocity_setpoint *= NAN;
|
||||
_acceleration_setpoint *= NAN;
|
||||
_thrust_setpoint *= NAN;
|
||||
_yaw_setpoint = _yawspeed_setpoint = NAN;
|
||||
}
|
||||
|
||||
bool FlightTask::_evaluateVehiclePosition()
|
||||
{
|
||||
if ((_time_stamp_current - _sub_vehicle_local_position->get().timestamp) < _timeout) {
|
||||
|
||||
Reference in New Issue
Block a user