Compare commits

..

No commits in common. "9061b175a721a10b24a311a8e43ae318f65c9e69" and "c6040899dd0833aebcd8541842b8521ab89c64bf" have entirely different histories.

5 changed files with 39 additions and 86 deletions

View File

@ -95,7 +95,7 @@ Send commands as simple text string terminated by `\n`. Responses are
formatted as line-delimited JSON.
| Syntax | Function |
|-------------------------------------------|-------------------------------------------------------------------------------|
|----------------------------------|-------------------------------------------------------------------------------|
| `report` | Show current input |
| `report mode` | Show current report mode |
| `report mode <off/on>` | Set report mode |
@ -104,7 +104,6 @@ formatted as line-delimited JSON.
| `pwm <0/1> max_i_neg <amp>` | Set maximum negative output current |
| `pwm <0/1> max_v <volt>` | Set maximum output voltage |
| `pwm <0/1> i_set <amp>` | Disengage PID, set fixed output current |
| `pwm <0/1> polarity_swapped <false/true>` | Swap current polarity on channel |
| `pwm <0/1> pid` | Let output current to be controlled by the PID |
| `center <0/1> <volt>` | Set the MAX1968 0A-centerpoint to the specified fixed voltage |
| `center <0/1> vref` | Set the MAX1968 0A-centerpoint to measure from VREF |

View File

@ -35,7 +35,6 @@ pub struct ChannelState {
pub pid_engaged: bool,
pub pid: pid::Controller,
pub sh: sh::Parameters,
pub polarity_swapped: bool,
}
impl ChannelState {
@ -52,7 +51,6 @@ impl ChannelState {
pid_engaged: false,
pid: pid::Controller::new(pid::Parameters::default()),
sh: sh::Parameters::default(),
polarity_swapped: false,
}
}

View File

@ -152,11 +152,7 @@ impl Channels {
}
pub fn set_i(&mut self, channel: usize, i_set: ElectricCurrent) -> ElectricCurrent {
let mut i_set = i_set.min(MAX_TEC_I).max(-MAX_TEC_I);
self.channel_state(channel).i_set = i_set;
if self.channel_state(channel).polarity_swapped {
i_set = -i_set;
}
let i_set = i_set.min(MAX_TEC_I).max(-MAX_TEC_I);
let vref_meas = match channel.into() {
0 => self.channel0.vref_meas,
1 => self.channel1.vref_meas,
@ -167,6 +163,7 @@ impl Channels {
let voltage = i_set * 10.0 * r_sense + center_point;
let voltage = self.set_dac(channel, voltage);
let i_set = (voltage - center_point) / (10.0 * r_sense);
self.channel_state(channel).i_set = i_set;
i_set
}
@ -410,12 +407,7 @@ impl Channels {
// Get current passing through TEC
pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent {
let tec_i = (self.adc_read(channel, PinsAdcReadTarget::ITec, 16) - self.adc_read(channel, PinsAdcReadTarget::VREF, 16)) / ElectricalResistance::new::<ohm>(0.4);
if self.channel_state(channel).polarity_swapped {
-tec_i
} else {
tec_i
}
(self.adc_read(channel, PinsAdcReadTarget::ITec, 16) - self.adc_read(channel, PinsAdcReadTarget::VREF, 16)) / ElectricalResistance::new::<ohm>(0.4)
}
// Get voltage across TEC
@ -487,7 +479,6 @@ impl Channels {
temperature: state.get_temperature()
.map(|temperature| temperature.get::<degree_celsius>()),
pid_engaged: state.pid_engaged,
current_swapped: state.polarity_swapped,
i_set,
dac_value,
dac_feedback: self.adc_read(channel, PinsAdcReadTarget::DacVfb, 1),
@ -586,7 +577,6 @@ pub struct Report {
sens: Option<ElectricalResistance>,
temperature: Option<f64>,
pid_engaged: bool,
current_swapped: bool,
i_set: ElectricCurrent,
dac_value: ElectricPotential,
dac_feedback: ElectricPotential,

View File

@ -181,15 +181,6 @@ impl Handler {
Ok(Handler::Handled)
}
fn swap_polarity (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, swapped: bool) -> Result<Handler, Error> {
channels.channel_state(channel).polarity_swapped = swapped;
let channel_state = channels.channel_state(channel);
let i_set = channel_state.i_set;
channels.set_i(channel, i_set);
send_line(socket, b"{}");
Ok(Handler::Handled)
}
fn set_pwm (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, pin: PwmPin, value: f64) -> Result<Handler, Error> {
match pin {
PwmPin::ISet => {
@ -433,7 +424,6 @@ impl Handler {
Command::Show(ShowCommand::PostFilter) => Handler::show_post_filter(socket, channels),
Command::Show(ShowCommand::Ipv4) => Handler::show_ipv4(socket, ipv4_config),
Command::PwmPid { channel } => Handler::engage_pid(socket, channels, channel),
Command::PwmPolaritySwapped { channel, swapped } => Handler::swap_polarity(socket, channels, channel, swapped),
Command::Pwm { channel, pin, value } => Handler::set_pwm(socket, channels, channel, pin, value),
Command::CenterPoint { channel, center } => Handler::set_center_point(socket, channels, channel, center),
Command::Pid { channel, parameter, value } => Handler::set_pid(socket, channels, channel, parameter, value),

View File

@ -159,10 +159,6 @@ pub enum Command {
PwmPid {
channel: usize,
},
PwmPolaritySwapped {
channel: usize,
swapped: bool,
},
CenterPoint {
channel: usize,
center: CenterPoint,
@ -243,12 +239,6 @@ fn off_on(input: &[u8]) -> IResult<&[u8], bool> {
))(input)
}
fn boolean(input: &[u8]) -> IResult<&[u8], bool> {
alt((value(false, tag("false")),
value(true, tag("true"))
))(input)
}
fn channel(input: &[u8]) -> IResult<&[u8], usize> {
map(one_of("01"), |c| (c as usize) - ('0' as usize))(input)
}
@ -331,16 +321,6 @@ fn pwm_pid(input: &[u8]) -> IResult<&[u8], ()> {
value((), tag("pid"))(input)
}
fn pwm_polarity_swapped(input: &[u8]) -> IResult<&[u8], bool> {
preceded(
tag("polarity_swapped"),
preceded(
whitespace,
boolean,
)
)(input)
}
fn pwm(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
let (input, _) = tag("pwm")(input)?;
alt((
@ -353,10 +333,6 @@ fn pwm(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
let (input, ()) = pwm_pid(input)?;
Ok((input, Ok(Command::PwmPid { channel })))
},
|input| {
let (input, swapped) = pwm_polarity_swapped(input)?;
Ok((input, Ok(Command::PwmPolaritySwapped { channel, swapped })))
},
|input| {
let (input, config) = pwm_setup(input)?;
match config {