Skip to content

Commit

Permalink
FlightTaskOrbit: parameter corrections from review
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR committed Oct 13, 2019
1 parent 64fb219 commit 2166b2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
5 changes: 1 addition & 4 deletions src/lib/FlightTasks/tasks/FlightTask/FlightTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ class FlightTask : public ModuleParams
/**
* Call this whenever a parameter update notification is received (parameter_update uORB message)
*/
void virtual handleParameterUpdate()
{
updateParams();
}
virtual void handleParameterUpdate() { updateParams(); }

/**
* Sets an external yaw handler which can be used by any flight task to implement a different yaw control strategy.
Expand Down
30 changes: 15 additions & 15 deletions src/lib/FlightTasks/tasks/Orbit/FlightTaskOrbit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ FlightTaskOrbit::FlightTaskOrbit() : _circle_approach_line(_position)

void FlightTaskOrbit::handleParameterUpdate()
{
updateParams();
FlightTask::handleParameterUpdate();

if (_param_flt_orb_v_max.get() > _param_mpc_xy_vel_max.get()) {
_param_flt_orb_v_max.set(_param_mpc_xy_vel_max.get());
_param_flt_orb_v_max.commit();
if (_param_orbit_vel_max.get() > _param_mpc_xy_vel_max.get()) {
_param_orbit_vel_max.set(_param_mpc_xy_vel_max.get());
_param_orbit_vel_max.commit();
mavlink_log_critical(&_mavlink_log_pub, "Orbit speed has been constrained by max speed")
}

if (_param_flt_orb_r_min.get() > _param_flt_orb_r_max.get()) {
_param_flt_orb_r_min.set(_param_flt_orb_r_max.get());
_param_flt_orb_r_min.commit();
if (_param_orbit_rad_min.get() > _param_orbit_rad_max.get()) {
_param_orbit_rad_min.set(_param_orbit_rad_max.get());
_param_orbit_rad_min.commit();
mavlink_log_critical(&_mavlink_log_pub, "Orbit minimum radius has been constrained by maximum radius")
}
}
Expand Down Expand Up @@ -131,11 +131,11 @@ bool FlightTaskOrbit::sendTelemetry()
bool FlightTaskOrbit::setRadius(float r)
{
// clip the radius to be within range
r = math::constrain(r, _param_flt_orb_r_min.get(), _param_flt_orb_r_max.get());
r = math::constrain(r, _param_orbit_rad_min.get(), _param_orbit_rad_max.get());

// small radius is more important than high velocity for safety
if (!checkAcceleration(r, _v, _param_flt_orb_a_max.get())) {
_v = math::sign(_v) * sqrtf(_param_flt_orb_a_max.get() * r);
if (!checkAcceleration(r, _v, _param_orbit_acc_max.get())) {
_v = math::sign(_v) * sqrtf(_param_orbit_acc_max.get() * r);
}

_r = r;
Expand All @@ -144,8 +144,8 @@ bool FlightTaskOrbit::setRadius(float r)

bool FlightTaskOrbit::setVelocity(const float v)
{
if (fabs(v) < _param_flt_orb_v_max.get() &&
checkAcceleration(_r, v, _param_flt_orb_a_max.get())) {
if (fabs(v) < _param_orbit_vel_max.get() &&
checkAcceleration(_r, v, _param_orbit_acc_max.get())) {
_v = v;
return true;
}
Expand All @@ -161,7 +161,7 @@ bool FlightTaskOrbit::checkAcceleration(float r, float v, float a)
bool FlightTaskOrbit::activate(vehicle_local_position_setpoint_s last_setpoint)
{
bool ret = FlightTaskManualAltitudeSmooth::activate(last_setpoint);
_r = _param_flt_orb_r_min.get();
_r = _param_orbit_rad_min.get();
_v = 1.f;
_center = Vector2f(_position);
_center(0) -= _r;
Expand All @@ -183,8 +183,8 @@ bool FlightTaskOrbit::update()
FlightTaskManualAltitudeSmooth::update();

// stick input adjusts parameters within a fixed time frame
const float r = _r - _sticks_expo(0) * _deltatime * (_param_flt_orb_r_max.get() / 8.f);
const float v = _v - _sticks_expo(1) * _deltatime * (_param_flt_orb_v_max.get() / 4.f);
const float r = _r - _sticks_expo(0) * _deltatime * (_param_orbit_rad_max.get() / 8.f);
const float v = _v - _sticks_expo(1) * _deltatime * (_param_orbit_vel_max.get() / 4.f);

setRadius(r);
setVelocity(v);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/FlightTasks/tasks/Orbit/FlightTaskOrbit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class FlightTaskOrbit : public FlightTaskManualAltitudeSmooth
DEFINE_PARAMETERS_CUSTOM_PARENT(FlightTaskManualAltitudeSmooth,
(ParamFloat<px4::params::MPC_XY_CRUISE>) _param_mpc_xy_cruise, /**< cruise speed for circle approach */
(ParamFloat<px4::params::MPC_XY_VEL_MAX>) _param_mpc_xy_vel_max,
(ParamFloat<px4::params::FLT_ORB_A_MAX>)_param_flt_orb_a_max,
(ParamFloat<px4::params::FLT_ORB_R_MIN>)_param_flt_orb_r_min,
(ParamFloat<px4::params::FLT_ORB_R_MAX>)_param_flt_orb_r_max,
(ParamFloat<px4::params::FLT_ORB_V_MAX>)_param_flt_orb_v_max
(ParamFloat<px4::params::ORBIT_ACC_MAX>) _param_orbit_acc_max,
(ParamFloat<px4::params::ORBIT_RAD_MIN>) _param_orbit_rad_min,
(ParamFloat<px4::params::ORBIT_RAD_MAX>) _param_orbit_rad_max,
(ParamFloat<px4::params::ORBIT_VEL_MAX>) _param_orbit_vel_max
)
};
8 changes: 4 additions & 4 deletions src/lib/FlightTasks/tasks/Orbit/FlightTaskOrbit_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @decimal 1
* @group FlightTaskOrbit
*/
PARAM_DEFINE_FLOAT(FLT_ORB_A_MAX, 2.0f);
PARAM_DEFINE_FLOAT(ORBIT_ACC_MAX, 2.0f);

/**
* Minimum radius of orbit
Expand All @@ -60,7 +60,7 @@ PARAM_DEFINE_FLOAT(FLT_ORB_A_MAX, 2.0f);
* @decimal 1
* @group FlightTaskOrbit
*/
PARAM_DEFINE_FLOAT(FLT_ORB_R_MIN, 1.0f);
PARAM_DEFINE_FLOAT(ORBIT_RAD_MIN, 1.0f);

/**
* Maximum radius of orbit
Expand All @@ -72,7 +72,7 @@ PARAM_DEFINE_FLOAT(FLT_ORB_R_MIN, 1.0f);
* @decimal 1
* @group FlightTaskOrbit
*/
PARAM_DEFINE_FLOAT(FLT_ORB_R_MAX, 400.0f);
PARAM_DEFINE_FLOAT(ORBIT_RAD_MAX, 100.0f);

/**
* Maximum speed
Expand All @@ -84,4 +84,4 @@ PARAM_DEFINE_FLOAT(FLT_ORB_R_MAX, 400.0f);
* @decimal 1
* @group FlightTaskOrbit
*/
PARAM_DEFINE_FLOAT(FLT_ORB_V_MAX, 10.0f);
PARAM_DEFINE_FLOAT(ORBIT_VEL_MAX, 10.0f);

0 comments on commit 2166b2f

Please sign in to comment.