Skip to content

Commit

Permalink
RC params refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Aug 1, 2017
1 parent d7cd82b commit 416547c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Mixer {
//otherwise values in pitch/roll/yaw would get clipped randomly and can produce random results
//in other words: we can't do angling if throttle is too low
if (controls.throttle < params_->min_armed_output) {
motor_outputs.assign(params_->motor_count, controls.throttle);
motor_outputs.assign(params_->motor_count, params_->min_armed_output);
return;
}

Expand Down
15 changes: 7 additions & 8 deletions AirLib/include/controllers/simple_flight/firmware/Params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ namespace simple_flight {

struct Params {
public:
uint16_t rc_channel_count = 12;
uint16_t rc_read_interval_ms = 10;
int16_t rc_thrust_channel = 2;
int16_t rc_pitch_channel = 3;
int16_t rc_roll_channel = 0;
int16_t rc_yaw_channel = 1;

int16_t rc_rate_angle_channel = 6; //corresponds to switch 3
struct Rc {
uint16_t channel_count = 12;
uint16_t read_interval_ms = 10;
int16_t rate_level_mode_channel = 6; //corresponds to switch 3 on FrSky Taranis

Axis4<int16_t> channels = Axis4<int16_t>(2, 0, 3, 1);
} rc;


//this should match up with target board
Expand Down
38 changes: 23 additions & 15 deletions AirLib/include/controllers/simple_flight/firmware/RemoteControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ class RemoteControl : public IGoalInput {
{
IGoalInput::reset();

rc_channels_.assign(params_->rc_channel_count, 0);
last_rec_read_ = 0;

goal_ = Axis4r();
goal_mode_ = params_->default_goal_mode;
channel_vals_.assign(params_->rc.channel_count, 0);
last_rec_read_ = 0;
}

virtual void update() override
Expand All @@ -34,30 +33,30 @@ class RemoteControl : public IGoalInput {
uint64_t time = clock_->millis();

//don't keep reading if not updated
if (time - last_rec_read_ <= params_->rc_read_interval_ms)
if (time - last_rec_read_ <= params_->rc.read_interval_ms)
return;

last_rec_read_ = time;

//read rc
for (uint16_t channel = 0; channel < params_->rc_channel_count; ++channel)
rc_channels_[channel] = board_inputs_->readChannel(channel);
for (uint16_t channel = 0; channel < params_->rc.channel_count; ++channel)
channel_vals_[channel] = board_inputs_->readChannel(channel);

goal_.throttle = rc_channels_[params_->rc_thrust_channel];
if (rc_channels_[params_->rc_rate_angle_channel] < 0.1f) { //approximately 0
goal_.throttle = channel_vals_[params_->rc.channels.throttle];
if (channel_vals_[params_->rc.rate_level_mode_channel] < 0.1f) { //approximately 0
goal_mode_ = GoalMode::getStandardAngleMode();

//we are in control-by-angles mode
goal_.axis3.pitch() = params_->max_angle_level.pitch() * rc_channels_[params_->rc_pitch_channel];
goal_.axis3.roll() = params_->max_angle_level.roll() * rc_channels_[params_->rc_roll_channel];
goal_.axis3.yaw() = params_->max_angle_level.yaw() * rc_channels_[params_->rc_yaw_channel];
goal_.axis3.pitch() = params_->max_angle_level.pitch() * channel_vals_[params_->rc.channels.axis3.pitch()];
goal_.axis3.roll() = params_->max_angle_level.roll() * channel_vals_[params_->rc_roll_channel];
goal_.axis3.yaw() = params_->max_angle_level.yaw() * channel_vals_[params_->rc_yaw_channel];
}
else { //we are in control-by-rate mode
goal_mode_ = GoalMode::getAllRateMode();

goal_.axis3.pitch() = params_->max_angle_rate.pitch() * rc_channels_[params_->rc_pitch_channel];
goal_.axis3.roll() = params_->max_angle_rate.roll() * rc_channels_[params_->rc_roll_channel];
goal_.axis3.yaw() = params_->max_angle_rate.yaw() * rc_channels_[params_->rc_yaw_channel];
goal_.axis3.pitch() = params_->max_angle_rate.pitch() * channel_vals_[params_->rc_pitch_channel];
goal_.axis3.roll() = params_->max_angle_rate.roll() * channel_vals_[params_->rc_roll_channel];
goal_.axis3.yaw() = params_->max_angle_rate.yaw() * channel_vals_[params_->rc_yaw_channel];
}

}
Expand All @@ -72,6 +71,15 @@ class RemoteControl : public IGoalInput {
return goal_mode_;
}

private:
enum class RcRequestType {
None, ArmRequest, DisarmRequest
};

RcRequestType getRcRequest()
{

}

private:
const IBoardClock* clock_;
Expand All @@ -81,7 +89,7 @@ class RemoteControl : public IGoalInput {
Axis4r goal_;
GoalMode goal_mode_;

std::vector<float> rc_channels_;
std::vector<float> channel_vals_;
uint64_t last_rec_read_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ class Axis3 {
};
typedef Axis3<TReal> Axis3r;

struct Axis4r {
TReal throttle = 0;
Axis3r axis3;
template<typename T>
struct Axis4 {
T throttle = 0;
Axis3<T> axis3;

Axis4(const T& throttle_val = T(), const T& x_val = T(), const T& y_val = T(), const T& z_val = T())
: throttle(throttle_val), axis(x_val, y_val, z_val)
{
}
};
typedef Axis4<TReal> Axis4r;


enum class GoalModeType {
AngleLevel,
Expand Down

0 comments on commit 416547c

Please sign in to comment.