Skip to content

Commit

Permalink
Rover : class Mode : Add const attribute to some 'getter' member func…
Browse files Browse the repository at this point in the history
…tion signatures.
  • Loading branch information
kwikius committed Feb 18, 2024
1 parent 1d08662 commit 2fe424d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions Rover/mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool Mode::enter()
// decode pilot steering and throttle inputs and return in steer_out and throttle_out arguments
// steering_out is in the range -4500 ~ +4500 with positive numbers meaning rotate clockwise
// throttle_out is in the range -100 ~ +100
void Mode::get_pilot_input(float &steering_out, float &throttle_out)
void Mode::get_pilot_input(float &steering_out, float &throttle_out) const
{
// no RC input means no throttle and centered steering
if (rover.failsafe.bits & FAILSAFE_EVENT_THROTTLE) {
Expand Down Expand Up @@ -102,7 +102,7 @@ void Mode::get_pilot_input(float &steering_out, float &throttle_out)
// decode pilot steering and throttle inputs and return in steer_out and throttle_out arguments
// steering_out is in the range -4500 ~ +4500 with positive numbers meaning rotate clockwise
// throttle_out is in the range -100 ~ +100
void Mode::get_pilot_desired_steering_and_throttle(float &steering_out, float &throttle_out)
void Mode::get_pilot_desired_steering_and_throttle(float &steering_out, float &throttle_out) const
{
// do basic conversion
get_pilot_input(steering_out, throttle_out);
Expand Down Expand Up @@ -130,7 +130,7 @@ void Mode::get_pilot_desired_steering_and_throttle(float &steering_out, float &t
}

// decode pilot steering and return steering_out and speed_out (in m/s)
void Mode::get_pilot_desired_steering_and_speed(float &steering_out, float &speed_out)
void Mode::get_pilot_desired_steering_and_speed(float &steering_out, float &speed_out) const
{
float desired_throttle;
get_pilot_input(steering_out, desired_throttle);
Expand All @@ -146,7 +146,7 @@ void Mode::get_pilot_desired_steering_and_speed(float &steering_out, float &spee
}

// decode pilot lateral movement input and return in lateral_out argument
void Mode::get_pilot_desired_lateral(float &lateral_out)
void Mode::get_pilot_desired_lateral(float &lateral_out) const
{
// no RC input means no lateral input
if ((rover.failsafe.bits & FAILSAFE_EVENT_THROTTLE) || (rover.channel_lateral == nullptr)) {
Expand All @@ -159,7 +159,7 @@ void Mode::get_pilot_desired_lateral(float &lateral_out)
}

// decode pilot's input and return heading_out (in cd) and speed_out (in m/s)
void Mode::get_pilot_desired_heading_and_speed(float &heading_out, float &speed_out)
void Mode::get_pilot_desired_heading_and_speed(float &heading_out, float &speed_out) const
{
// get steering and throttle in the -1 to +1 range
float desired_steering = constrain_float(rover.channel_steer->norm_input_dz(), -1.0f, 1.0f);
Expand All @@ -183,7 +183,7 @@ void Mode::get_pilot_desired_heading_and_speed(float &heading_out, float &speed_

// decode pilot roll and pitch inputs and return in roll_out and pitch_out arguments
// outputs are in the range -1 to +1
void Mode::get_pilot_desired_roll_and_pitch(float &roll_out, float &pitch_out)
void Mode::get_pilot_desired_roll_and_pitch(float &roll_out, float &pitch_out) const
{
if (channel_roll != nullptr) {
roll_out = channel_roll->norm_input();
Expand All @@ -199,7 +199,7 @@ void Mode::get_pilot_desired_roll_and_pitch(float &roll_out, float &pitch_out)

// decode pilot walking_height inputs and return in walking_height_out arguments
// outputs are in the range -1 to +1
void Mode::get_pilot_desired_walking_height(float &walking_height_out)
void Mode::get_pilot_desired_walking_height(float &walking_height_out) const
{
if (channel_walking_height != nullptr) {
walking_height_out = channel_walking_height->norm_input();
Expand Down
16 changes: 8 additions & 8 deletions Rover/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,24 @@ class Mode
// decode pilot steering and throttle inputs and return in steer_out and throttle_out arguments
// steering_out is in the range -4500 ~ +4500 with positive numbers meaning rotate clockwise
// throttle_out is in the range -100 ~ +100
void get_pilot_desired_steering_and_throttle(float &steering_out, float &throttle_out);
void get_pilot_desired_steering_and_throttle(float &steering_out, float &throttle_out) const;

// decode pilot input steering and return steering_out and speed_out (in m/s)
void get_pilot_desired_steering_and_speed(float &steering_out, float &speed_out);
void get_pilot_desired_steering_and_speed(float &steering_out, float &speed_out) const;

// decode pilot lateral movement input and return in lateral_out argument
void get_pilot_desired_lateral(float &lateral_out);
void get_pilot_desired_lateral(float &lateral_out) const;

// decode pilot's input and return heading_out (in cd) and speed_out (in m/s)
void get_pilot_desired_heading_and_speed(float &heading_out, float &speed_out);
void get_pilot_desired_heading_and_speed(float &heading_out, float &speed_out) const;

// decode pilot roll and pitch inputs and return in roll_out and pitch_out arguments
// outputs are in the range -1 to +1
void get_pilot_desired_roll_and_pitch(float &roll_out, float &pitch_out);
void get_pilot_desired_roll_and_pitch(float &roll_out, float &pitch_out) const;

// decode pilot height inputs and return in height_out arguments
// outputs are in the range -1 to +1
void get_pilot_desired_walking_height(float &walking_height_out);
void get_pilot_desired_walking_height(float &walking_height_out) const;

// high level call to navigate to waypoint
void navigate_to_waypoint();
Expand Down Expand Up @@ -192,7 +192,7 @@ class Mode
// decode pilot steering and throttle inputs and return in steer_out and throttle_out arguments
// steering_out is in the range -4500 ~ +4500 with positive numbers meaning rotate clockwise
// throttle_out is in the range -100 ~ +100
void get_pilot_input(float &steering_out, float &throttle_out);
void get_pilot_input(float &steering_out, float &throttle_out) const;
void set_steering(float steering_value);

// references to avoid code churn:
Expand Down Expand Up @@ -745,7 +745,7 @@ class ModeSmartRTL : public Mode
bool _loitering; // true if loitering at end of SRTL
};



class ModeSteering : public Mode
{
Expand Down

0 comments on commit 2fe424d

Please sign in to comment.