Rename PWM concepts in code to output
Things like max_v, max_i_pos, max_i_neg should be deemed "output limits" and not simply "pwm" or "pwm_limits", as having PWM driving those pins on the MAX1968 is an implementation detail.
This commit is contained in:
parent
9868ca4447
commit
0dc7b248b7
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
ad7172, b_parameter as bp,
|
||||
command_parser::{CenterPoint, Polarity},
|
||||
config::PwmLimits,
|
||||
config::OutputLimits,
|
||||
pid,
|
||||
};
|
||||
use num_traits::Zero;
|
||||
@ -29,7 +29,7 @@ pub struct ChannelState {
|
||||
pub center: CenterPoint,
|
||||
pub dac_value: ElectricPotential,
|
||||
pub i_set: ElectricCurrent,
|
||||
pub pwm_limits: PwmLimits,
|
||||
pub output_limits: OutputLimits,
|
||||
pub pid_engaged: bool,
|
||||
pub pid: pid::Controller,
|
||||
pub bp: bp::Parameters,
|
||||
@ -47,7 +47,7 @@ impl ChannelState {
|
||||
center: CenterPoint::VRef,
|
||||
dac_value: ElectricPotential::new::<volt>(0.0),
|
||||
i_set: ElectricCurrent::new::<ampere>(0.0),
|
||||
pwm_limits: PwmLimits {
|
||||
output_limits: OutputLimits {
|
||||
max_v: ElectricPotential::zero(),
|
||||
max_i_pos: ElectricCurrent::zero(),
|
||||
max_i_neg: ElectricCurrent::zero(),
|
||||
|
@ -363,15 +363,15 @@ impl Channels {
|
||||
}
|
||||
|
||||
pub fn get_max_v(&mut self, channel: usize) -> ElectricPotential {
|
||||
self.channel_state(channel).pwm_limits.max_v
|
||||
self.channel_state(channel).output_limits.max_v
|
||||
}
|
||||
|
||||
pub fn get_max_i_pos(&mut self, channel: usize) -> ElectricCurrent {
|
||||
self.channel_state(channel).pwm_limits.max_i_pos
|
||||
self.channel_state(channel).output_limits.max_i_pos
|
||||
}
|
||||
|
||||
pub fn get_max_i_neg(&mut self, channel: usize) -> ElectricCurrent {
|
||||
self.channel_state(channel).pwm_limits.max_i_neg
|
||||
self.channel_state(channel).output_limits.max_i_neg
|
||||
}
|
||||
|
||||
// Get current passing through TEC
|
||||
@ -419,7 +419,7 @@ impl Channels {
|
||||
let max_v = max_v.min(MAX_TEC_V).max(ElectricPotential::zero());
|
||||
let duty = (max_v / max).get::<ratio>();
|
||||
let duty = self.set_pwm(channel, PwmPin::MaxV, duty);
|
||||
self.channel_state(channel).pwm_limits.max_v = max_v;
|
||||
self.channel_state(channel).output_limits.max_v = max_v;
|
||||
(duty * max, max)
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ impl Channels {
|
||||
Polarity::Normal => self.set_pwm(channel, PwmPin::MaxIPos, duty),
|
||||
Polarity::Reversed => self.set_pwm(channel, PwmPin::MaxINeg, duty),
|
||||
};
|
||||
self.channel_state(channel).pwm_limits.max_i_pos = max_i_pos;
|
||||
self.channel_state(channel).output_limits.max_i_pos = max_i_pos;
|
||||
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, max)
|
||||
}
|
||||
|
||||
@ -451,7 +451,7 @@ impl Channels {
|
||||
Polarity::Normal => self.set_pwm(channel, PwmPin::MaxINeg, duty),
|
||||
Polarity::Reversed => self.set_pwm(channel, PwmPin::MaxIPos, duty),
|
||||
};
|
||||
self.channel_state(channel).pwm_limits.max_i_neg = max_i_neg;
|
||||
self.channel_state(channel).output_limits.max_i_neg = max_i_neg;
|
||||
(duty * MAX_TEC_I_DUTY_TO_CURRENT_RATE, max)
|
||||
}
|
||||
|
||||
|
@ -99,13 +99,13 @@ impl Handler {
|
||||
Ok(Handler::Handled)
|
||||
}
|
||||
|
||||
fn show_pwm(socket: &mut TcpSocket, channels: &mut Channels) -> Result<Handler, Error> {
|
||||
fn show_output(socket: &mut TcpSocket, channels: &mut Channels) -> Result<Handler, Error> {
|
||||
match channels.output_summaries_json() {
|
||||
Ok(buf) => {
|
||||
send_line(socket, &buf);
|
||||
}
|
||||
Err(e) => {
|
||||
error!("unable to serialize pwm summary: {:?}", e);
|
||||
error!("unable to serialize output summary: {:?}", e);
|
||||
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
|
||||
return Err(Error::Report);
|
||||
}
|
||||
@ -170,7 +170,7 @@ impl Handler {
|
||||
Ok(Handler::Handled)
|
||||
}
|
||||
|
||||
fn set_pwm(
|
||||
fn set_output(
|
||||
socket: &mut TcpSocket,
|
||||
channels: &mut Channels,
|
||||
channel: usize,
|
||||
@ -476,7 +476,7 @@ impl Handler {
|
||||
Command::Quit => Ok(Handler::CloseSocket),
|
||||
Command::Show(ShowCommand::Input) => Handler::show_report(socket, channels),
|
||||
Command::Show(ShowCommand::Pid) => Handler::show_pid(socket, channels),
|
||||
Command::Show(ShowCommand::Output) => Handler::show_pwm(socket, channels),
|
||||
Command::Show(ShowCommand::Output) => Handler::show_output(socket, channels),
|
||||
Command::Show(ShowCommand::BParameter) => Handler::show_b_parameter(socket, channels),
|
||||
Command::Show(ShowCommand::PostFilter) => Handler::show_post_filter(socket, channels),
|
||||
Command::Show(ShowCommand::Ipv4) => Handler::show_ipv4(socket, ipv4_config),
|
||||
@ -488,7 +488,7 @@ impl Handler {
|
||||
channel,
|
||||
pin,
|
||||
value,
|
||||
} => Handler::set_pwm(socket, channels, channel, pin, value),
|
||||
} => Handler::set_output(socket, channels, channel, pin, value),
|
||||
Command::CenterPoint { channel, center } => {
|
||||
Handler::set_center_point(socket, channels, channel, center)
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ pub enum Command {
|
||||
Reset,
|
||||
Ipv4(Ipv4Config),
|
||||
Show(ShowCommand),
|
||||
/// PWM parameter setting
|
||||
/// Output parameter setting
|
||||
Output {
|
||||
channel: usize,
|
||||
pin: PwmPin,
|
||||
|
@ -18,14 +18,14 @@ pub struct ChannelConfig {
|
||||
i_set: ElectricCurrent,
|
||||
polarity: Polarity,
|
||||
bp: b_parameter::Parameters,
|
||||
pwm: PwmLimits,
|
||||
output_limits: OutputLimits,
|
||||
/// uses variant `PostFilter::Invalid` instead of `None` to save space
|
||||
adc_postfilter: PostFilter,
|
||||
}
|
||||
|
||||
impl ChannelConfig {
|
||||
pub fn new(channels: &mut Channels, channel: usize) -> Self {
|
||||
let pwm = PwmLimits::new(channels, channel);
|
||||
let output_limits = OutputLimits::new(channels, channel);
|
||||
|
||||
let adc_postfilter = channels
|
||||
.adc
|
||||
@ -47,7 +47,7 @@ impl ChannelConfig {
|
||||
i_set,
|
||||
polarity: state.polarity.clone(),
|
||||
bp: state.bp.clone(),
|
||||
pwm,
|
||||
output_limits,
|
||||
adc_postfilter,
|
||||
}
|
||||
}
|
||||
@ -60,7 +60,7 @@ impl ChannelConfig {
|
||||
state.pid_engaged = self.pid_engaged;
|
||||
state.bp = self.bp.clone();
|
||||
|
||||
self.pwm.apply(channels, channel);
|
||||
self.output_limits.apply(channels, channel);
|
||||
|
||||
let adc_postfilter = match self.adc_postfilter {
|
||||
PostFilter::Invalid => None,
|
||||
@ -73,18 +73,18 @@ impl ChannelConfig {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PwmLimits {
|
||||
pub struct OutputLimits {
|
||||
pub max_v: ElectricPotential,
|
||||
pub max_i_pos: ElectricCurrent,
|
||||
pub max_i_neg: ElectricCurrent,
|
||||
}
|
||||
|
||||
impl PwmLimits {
|
||||
impl OutputLimits {
|
||||
pub fn new(channels: &mut Channels, channel: usize) -> Self {
|
||||
let max_v = channels.get_max_v(channel);
|
||||
let max_i_pos = channels.get_max_i_pos(channel);
|
||||
let max_i_neg = channels.get_max_i_neg(channel);
|
||||
PwmLimits {
|
||||
OutputLimits {
|
||||
max_v,
|
||||
max_i_pos,
|
||||
max_i_neg,
|
||||
|
Loading…
Reference in New Issue
Block a user