mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 16:53:34 +08:00
FlightTasks: Various review refactoring
This commit is contained in:
@@ -79,7 +79,7 @@ int FlightTasks::switchTask(int task_number)
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool FlightTasks::_updateCommand()
|
||||
void FlightTasks::_updateCommand()
|
||||
{
|
||||
/* lazy subscription to command topic */
|
||||
if (_sub_vehicle_command < 0) {
|
||||
@@ -91,19 +91,19 @@ bool FlightTasks::_updateCommand()
|
||||
orb_check(_sub_vehicle_command, &updated);
|
||||
|
||||
if (!updated) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
/* check if command is for flight task library */
|
||||
struct vehicle_command_s command;
|
||||
orb_copy(ORB_ID(vehicle_command), _sub_vehicle_command, &command);
|
||||
|
||||
if (!(command.command == vehicle_command_s::VEHICLE_CMD_FLIGHT_TASK)) {
|
||||
return false;
|
||||
if (command.command != vehicle_command_s::VEHICLE_CMD_FLIGHT_TASK) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* evaluate command */
|
||||
int switch_result = switchTask(int(command.param1));
|
||||
int switch_result = switchTask(int(command.param1 + 0.5f));
|
||||
uint8_t cmd_result = vehicle_command_ack_s::VEHICLE_RESULT_FAILED;
|
||||
|
||||
/* if we are in the desired task */
|
||||
@@ -138,6 +138,4 @@ bool FlightTasks::_updateCommand()
|
||||
orb_publish(ORB_ID(vehicle_command_ack), _pub_vehicle_command_ack, &command_ack);
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,13 +71,12 @@ public:
|
||||
|
||||
/**
|
||||
* Get the output data from the current task
|
||||
* Only call when task is active!
|
||||
* @return output setpoint, to be executed by position control
|
||||
*/
|
||||
const vehicle_local_position_setpoint_s &getPositionSetpoint();
|
||||
|
||||
/**
|
||||
* Convenient operator to get the output data from the current task
|
||||
* Only call when task is active!
|
||||
*/
|
||||
inline const vehicle_local_position_setpoint_s &operator()() { return getPositionSetpoint(); }
|
||||
|
||||
@@ -121,7 +120,7 @@ private:
|
||||
|
||||
FlightTaskManual manual;
|
||||
FlightTaskOrbit orbit;
|
||||
} _task_union; /*< storage for the currently active task */
|
||||
} _task_union; /**< storage for the currently active task */
|
||||
|
||||
FlightTask *_current_task = nullptr;
|
||||
int _current_task_index = -1;
|
||||
@@ -130,9 +129,8 @@ private:
|
||||
|
||||
/**
|
||||
* Check for vehicle commands (received via MAVLink), evaluate and acknowledge them
|
||||
* @return true if there was a new command, false if not
|
||||
*/
|
||||
bool _updateCommand();
|
||||
int _sub_vehicle_command = -1; /*< topic handle on which commands are received */
|
||||
orb_advert_t _pub_vehicle_command_ack = nullptr; /*< topic handle to which commands get acknowledged */
|
||||
void _updateCommand();
|
||||
int _sub_vehicle_command = -1; /**< topic handle on which commands are received */
|
||||
orb_advert_t _pub_vehicle_command_ack = nullptr; /**< topic handle to which commands get acknowledged */
|
||||
};
|
||||
|
||||
@@ -56,8 +56,7 @@ bool FlightTaskOrbit::applyCommandParameters(const vehicle_command_s &command)
|
||||
const float &r = command.param3; /**< commanded radius */
|
||||
const float &v = command.param4; /**< commanded velocity */
|
||||
|
||||
if (math::isInRange(r, 5.f, 50.f) &&
|
||||
fabs(v) < 10.f) {
|
||||
if (math::isInRange(r, 5.f, 50.f) && fabs(v) < 10.f) {
|
||||
_r = r;
|
||||
_v = v;
|
||||
return FlightTaskManual::applyCommandParameters(command);
|
||||
|
||||
Reference in New Issue
Block a user