Skip to content

Commit

Permalink
Fix style after rebasing on fixed format check
Browse files Browse the repository at this point in the history
  • Loading branch information
MaEtUgR committed May 28, 2019
1 parent 41037bf commit 43ec3a5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool FlightTaskManualAcceleration::initializeSubscriptions(SubscriptionArray &su
if (!FlightTaskManual::initializeSubscriptions(subscription_array)) {
return false;
}

return true;
}

Expand All @@ -69,8 +70,10 @@ bool FlightTaskManualAcceleration::activate()
bool FlightTaskManualAcceleration::update()
{
// Yaw
_position_lock.updateYawFromStick(_yawspeed_setpoint, _yaw_setpoint, _sticks_expo(3) * math::radians(_param_mpc_man_y_max.get()), _yaw, _deltatime);
_yaw_setpoint = _position_lock.updateYawReset(_yaw_setpoint, _sub_attitude->get().quat_reset_counter, Quatf(_sub_attitude->get().delta_q_reset));
_position_lock.updateYawFromStick(_yawspeed_setpoint, _yaw_setpoint,
_sticks_expo(3) * math::radians(_param_mpc_man_y_max.get()), _yaw, _deltatime);
_yaw_setpoint = _position_lock.updateYawReset(_yaw_setpoint, _sub_attitude->get().quat_reset_counter,
Quatf(_sub_attitude->get().delta_q_reset));

// Map sticks input to acceleration
_acceleration_setpoint = Vector3f(&_sticks_expo(0)) * 10;
Expand All @@ -81,7 +84,8 @@ bool FlightTaskManualAcceleration::update()

// Rotate horizontal acceleration input to body heading
float yaw_rotate = PX4_ISFINITE(_yaw_setpoint) ? _yaw_setpoint : _yaw;
Vector3f v_r = Vector3f(Dcmf(Eulerf(0.0f, 0.0f, yaw_rotate)) * Vector3f(_acceleration_setpoint(0), _acceleration_setpoint(1), 0.0f));
Vector3f v_r = Vector3f(Dcmf(Eulerf(0.0f, 0.0f, yaw_rotate)) * Vector3f(_acceleration_setpoint(0),
_acceleration_setpoint(1), 0.0f));
_acceleration_setpoint(0) = v_r(0);
_acceleration_setpoint(1) = v_r(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ bool FlightTaskManualAltitude::activate()
void FlightTaskManualAltitude::_scaleSticks()
{
// Use sticks input with deadzone and exponential curve for vertical velocity and yawspeed
_position_lock.updateYawFromStick(_yawspeed_setpoint, _yaw_setpoint, _sticks_expo(3) * math::radians(_param_mpc_man_y_max.get()), _yaw, _deltatime);
_yaw_setpoint = _position_lock.updateYawReset(_yaw_setpoint, _sub_attitude->get().quat_reset_counter, Quatf(_sub_attitude->get().delta_q_reset));
_position_lock.updateYawFromStick(_yawspeed_setpoint, _yaw_setpoint,
_sticks_expo(3) * math::radians(_param_mpc_man_y_max.get()), _yaw, _deltatime);
_yaw_setpoint = _position_lock.updateYawReset(_yaw_setpoint, _sub_attitude->get().quat_reset_counter,
Quatf(_sub_attitude->get().delta_q_reset));

const float vel_max_z = (_sticks(2) > 0.0f) ? _constraints.speed_down : _constraints.speed_up;
_velocity_setpoint(2) = vel_max_z * _sticks_expo(2);
Expand Down
11 changes: 8 additions & 3 deletions src/lib/FlightTasks/tasks/Utility/PositionLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class PositionLock
* @param yaw_stick_input current yaw rotational rate state
* @return yaw setpoint to execute to have a yaw lock at the correct moment in time
*/
void updateYawFromStick(float &yawspeed_setpoint, float &yaw_setpoint, const float desired_yawspeed, const float yaw, const float dt) {
void updateYawFromStick(float &yawspeed_setpoint, float &yaw_setpoint, const float desired_yawspeed, const float yaw,
const float dt)
{
_yawspeed_slew_rate.setSlewRate(1.f);
yawspeed_setpoint = _yawspeed_slew_rate.update(desired_yawspeed, dt);
yaw_setpoint = updateYawLock(yaw, yawspeed_setpoint, yaw_setpoint);
Expand All @@ -75,7 +77,8 @@ class PositionLock
* @param yaw current yaw setpoint which then will be overwritten by the return value
* @return yaw setpoint to execute to have a yaw lock at the correct moment in time
*/
static float updateYawLock(const float yaw, const float yawspeed_setpoint, const float yaw_setpoint) {
static float updateYawLock(const float yaw, const float yawspeed_setpoint, const float yaw_setpoint)
{
// Yaw-lock depends on desired yawspeed input. If not locked, yaw_sp is set to NAN.
if (fabsf(yawspeed_setpoint) > FLT_EPSILON) {
// no fixed heading when rotating around yaw by stick
Expand All @@ -98,12 +101,14 @@ class PositionLock
* @param delta_q_reset rotation offset from the last reset that happened
* @return updated yaw setpoint to use with reference reset taken into account
*/
float updateYawReset(const float yaw_setpoint, const uint8_t yaw_reset_counter, const matrix::Quatf delta_q_reset) {
float updateYawReset(const float yaw_setpoint, const uint8_t yaw_reset_counter, const matrix::Quatf delta_q_reset)
{
// check if reset counter changed and update yaw setpoint if necessary
if (yaw_reset_counter != _yaw_reset_counter) {
_yaw_reset_counter = yaw_reset_counter;
return yaw_setpoint + matrix::Eulerf(delta_q_reset).psi();
}

return yaw_setpoint;
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib/SlewRate/SlewRate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class SlewRate
* @param deltatime time in seconds since last update
* @return actual value that complies with the slew rate
*/
Type update(const Type new_value, const float deltatime) {
Type update(const Type new_value, const float deltatime)
{
// Limit the rate of change of the value
const float dvalue_desired = new_value - _value;
const float dvalue_max = _slew_rate * deltatime;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/SlewRate/SlewRateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ TEST(AttitudeControlTest, SlewUpLimited)
SlewRate<float> _slew_rate;
_slew_rate.setSlewRate(.1f);
_slew_rate.setForcedValue(-5.5f);

for (int i = 1; i <= 10; i++) {
EXPECT_FLOAT_EQ(_slew_rate.update(20.f, .2f), -5.5f + i * .02f);
}
Expand All @@ -49,6 +50,7 @@ TEST(AttitudeControlTest, SlewDownLimited)
SlewRate<float> _slew_rate;
_slew_rate.setSlewRate(1.1f);
_slew_rate.setForcedValue(17.3f);

for (int i = 1; i <= 10; i++) {
EXPECT_FLOAT_EQ(_slew_rate.update(-50.f, .3f), 17.3f - i * .33f);
}
Expand All @@ -59,9 +61,11 @@ TEST(AttitudeControlTest, ReachValueSlewed)
SlewRate<float> _slew_rate;
_slew_rate.setSlewRate(.2f);
_slew_rate.setForcedValue(8.f);

for (int i = 1; i <= 10; i++) {
EXPECT_FLOAT_EQ(_slew_rate.update(10.f, 1.f), 8.f + i * .2f);
}

for (int i = 1; i <= 10; i++) {
EXPECT_FLOAT_EQ(_slew_rate.update(10.f, 1.f), 10.f);
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/mc_pos_control/Utility/ControlMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ vehicle_attitude_setpoint_s accelerationToAttitude(const Vector3f &acc_sp, const
return att_sp;
}

vehicle_attitude_setpoint_s bodyzToAttitude(Vector3f body_z, const float yaw_sp) {
vehicle_attitude_setpoint_s bodyzToAttitude(Vector3f body_z, const float yaw_sp)
{
vehicle_attitude_setpoint_s att_sp = {};
att_sp.yaw_body = yaw_sp;

Expand Down
3 changes: 2 additions & 1 deletion src/modules/mc_pos_control/Utility/ControlMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ vehicle_attitude_setpoint_s thrustToAttitude(const matrix::Vector3f &thr_sp, con
* @param yaw_sp the desired yaw setpoint
* @return vehicle_attitude_setpoints_s struct for attitude controller
*/
vehicle_attitude_setpoint_s accelerationToAttitude(const matrix::Vector3f &acc_sp, const float yaw_sp, const float hover_thrust);
vehicle_attitude_setpoint_s accelerationToAttitude(const matrix::Vector3f &acc_sp, const float yaw_sp,
const float hover_thrust);

/**
* Converts a body z vector and yaw set-point to a desired attitude.
Expand Down

0 comments on commit 43ec3a5

Please sign in to comment.