Skip to main content

Controller

Struct Controller 

Source
pub struct Controller {
    pub payload_attached: bool,
    pub valves: Vec<f64>,
    pub drives: Vec<Drive>,
    pub set_pos: Vec<f64>,
    pub set_vel: Vec<f64>,
    pub set_acc: Vec<f64>,
    pub tool_error: Vec<f64>,
    pub setpoint_offset: Vec<f64>,
    pub fault: Option<Fault>,
    /* private fields */
}

Fields§

§payload_attached: bool§valves: Vec<f64>

The command of each valve of Machine::valves (+1 extend, -1 retract, 0 centre), set by the cycle’s segments; the simulation hands them to the machine every step.

§drives: Vec<Drive>§set_pos: Vec<f64>

Tool-side setpoints and following error.

§set_vel: Vec<f64>§set_acc: Vec<f64>§tool_error: Vec<f64>§setpoint_offset: Vec<f64>

Added to the position setpoint only, not to the feedforward: a test signal for the closed loop (step response, frequency response).

§fault: Option<Fault>

The first trip since the drives were last enabled (effects.drive_monitoring).

Implementations§

Source§

impl Controller

Source

pub fn new( cfg: &Config, machine: &dyn Machine, state: &[f64], ) -> Result<Self, ConfigError>

A controller at rest at the machine’s current state.

Source

pub fn apply_config( &mut self, cfg: &Config, machine: &dyn Machine, ) -> Result<(), ConfigError>

Re-reads gains, switches, cycle times and the cycle; keeps the loops’ running state. A config with a refused value changes nothing.

Source

pub fn command( &mut self, command: Command, machine: &dyn Machine, ) -> Result<(), CommandError>

Source

pub fn set_drive_mode( &mut self, k: usize, mode: DriveMode, machine: &dyn Machine, state: &[f64], ) -> Result<(), CommandError>

Puts motor k’s drive in mode (DriveMode), state the machine’s. Refused while the drives are off or stopping after a trip, and out of position mode while a move, cycle or path runs; while a drive is out of position mode, the plan commands are refused. A drive coming back to position mode takes the plan with it: the plan stands where the motors stand, at rest, and every drive starts its PI from the torque it asked for last (Drive::set_mode), so the torque does not jump; at speed, the position loop then brings the motors back to where they were at the switch. Enabling the drives puts them all in position mode.

Source

pub fn step_brake(&mut self, dt: f64)

One base step of dt of the holding brakes’ command: they engage brake.engage_delay_s after they are asked to hold and release release_delay_s after they are asked to let go (effects.brake_delay; at once without it).

Source

pub fn brake_engaged(&self) -> bool

Whether the holding brakes hold (step_brake).

Source

pub fn reacting(&self) -> bool

Whether the drives are stopping after a trip (react).

Source

pub fn halting(&self) -> bool

Whether a category 2 stop (StopCategory::Two) is braking the plan.

Source

pub fn fault_reaction(&self, k: usize) -> Reaction

Each drive’s fault reaction (effects.drive_monitoring).

Source

pub fn plan_path( &self, machine: &dyn Machine, pieces: &[Piece], time_optimal: bool, ) -> Result<Vec<(f64, Vec<f64>)>, CommandError>

The timing for a path of lines and arcs from where the setpoint stands, as the poses that Command::Trajectory runs: within the axis limits, or as fast as the motors allow (see path).

Source

pub fn plan_program( &self, machine: &dyn Machine, runs: &[Run], time_optimal: bool, ) -> Result<Vec<(f64, Vec<f64>)>, CommandError>

The timing for a program (program::read) from where the setpoint stands, as the poses Command::Trajectory runs: each run planned from where the one before ends, at rest between them, within the corner tolerance of its G61 or G64. A run with a feed is planned within the axis limits with the speed along the path of each piece capped at its own feed times profile.feed_override (path::plan_feeds); one without as plan_path plans it, as fast as the motors allow with time_optimal. A dwell (G4) holds the last pose for its time, in whole profile cycles, as a cycle segment’s dwell does. A program without a move is refused (error-path).

Source

pub fn path_deviation( &self, machine: &dyn Machine, pieces: &[Piece], time_optimal: bool, ) -> Result<f64, CommandError>

How far the path plan_path plans for these pieces is from the pieces as given, at most (see path::deviation): zero unless profile.path_tolerance_m allows transition curves. The time-optimal plan’s curves are as long as the motors’ speeds need, so its deviation can differ. A path plan_path refuses is refused here the same way (it is planned for that).

Source

pub fn program_deviations( &self, machine: &dyn Machine, runs: &[Run], time_optimal: bool, ) -> Result<Vec<f64>, CommandError>

path_deviation per run of a program (plan_program: each run from where the one before ends, a run with a feed within the axis limits). A run with a feed reads as without its feeds (path::deviation): never lower than its own path’s.

Source

pub fn busy(&self) -> bool

True while a move, a dwell or the cycle is under way.

Source

pub fn enabled(&self) -> bool

False between Command::Disable and Command::Enable.

Source

pub fn cycle_segment(&self) -> Option<usize>

Source

pub fn conveyor(&self) -> Option<(&Conveyor, Option<&Pass>)>

The conveyor of [conveyor], where the config has one, and the pass of its cycle under way or last run.

Source

pub fn cycle_passes(&self) -> u64

How often the cycle has started its first segment since the controller was made. The segment index alone does not tell one pass from the next when the cycle has a single segment.

Source

pub fn cam_master(&self) -> f64

Where an electronic cam’s master stands (Machine::cam), in its units; kept between runs.

Source

pub fn torque_curve(&self, speed: f64) -> (f64, f64)

The torque the drives can give at a motor speed: (lowest, highest).

Source

pub fn motor_torque_curve(&self, k: usize, speed: f64) -> (f64, f64)

The torque motor k’s drive can give at a motor speed: (lowest, highest).

Source

pub fn dwell_progress(&self) -> Option<f64>

How far a dwell of the cycle has run, from 0 to 1; None outside a dwell.

Source

pub fn gripper_acting(&self) -> bool

Whether the gripper is closing or opening (effects.gripper_time).

Source

pub fn planned_pos(&self) -> &[f64]

The setpoint as planned, before input shaping: during a dwell, the target.

Source

pub fn external_setpoint(&self) -> &[f64]

Where a setpoint from outside would leave from: the target of the one the controller still interpolates towards, else where the plan stands. A link to a PLC shows this as its setpoint, so that an axis the PLC does not write stays where it is.

Source

pub fn rated_torque(&self) -> f64

The torque the motors can give continuously.

Source

pub fn drive_params(&self) -> &DriveParams

Motor and drive data, for the analysis.

Source

pub fn plan_limits(&self) -> &PlanLimits

The limits the time-optimal plan keeps beside the motors’ (path::PlanLimits), as the config gives them.

Motor k’s DC link room above the bus, J: 1/2 C (U_threshold^2 - U_bus^2) of its own ratings; None without them.

Source

pub fn drive_params_of(&self, k: usize) -> &DriveParams

Motor and drive data of motor k: drive_params with that motor’s own values (catalog::motor_config).

Source

pub fn unrounded_encoders(&mut self)

Every motor encoder without its rounding to counts and its noise, the speed still their difference per cycle (DriveParams::speed_from_positions): for the small-signal loop measurement (analysis::velocity_loop_response), whose test swing at high frequencies is a fraction of a count (a mover’s 3 N swings it 0.03 um at 1.6 kHz against 1 um counts): with them the rounding, not the loop, is measured.

Source

pub fn motor_drives(&self, machine: &dyn Machine) -> Vec<&DriveParams>

Each motor’s own drive and motor data (drive_params_of), in the order of Machine::motors.

Source

pub fn motors_shifted(&mut self, shift: &[f64])

The motors stand shift from where they stood without having turned there: the machine’s model was exchanged, and belt stretch and gear twist came or went with it, or its ratio changed. The encoders’ last readings move along, so that the step does not read as speed, and so do the position setpoints at the drives and on the fieldbus, so that it does not read as following error. The next profile cycle works them out anew.

Source

pub fn update( &mut self, step: u64, machine: &dyn Machine, state: &[f64], torque: &mut [f64], )

One base step: runs whichever loops are due and sets the voltages the windings get over the step. Enabled, the simulation then takes windings and mechanics through the step together and hands the windings back (winding_stepped). Disabled, the drives give no torque, their windings cool and their DC links discharge, and torque is zero.

Source

pub fn plan_now(&self, time: f64, out: &mut [f64])

The tool setpoint at time: the last profile cycle’s run on by its speed and acceleration, as the drives’ fine interpolation runs the motors’ on (at most one profile cycle). What the analysis measures the tool against.

Source

pub fn setpoint_age(&self, time: f64) -> f64

How long ago, at time, the profile cycle set set_pos, set_vel and set_acc (the signal setpoint_age): plan_now is those run on by it.

Source

pub fn winding_stepped( &mut self, windings: &[f64], angle: &[f64], speed: &[f64], )

The base step done (see update): per drive the current at its end and the electrical energy, copper loss and work on the shaft over it, WINDING_STATES numbers per drive in their order, and the rotors’ angles and speeds at its end. Then the shared DC link, and the trip.

Source

pub fn shaper_halves( &self, machine: &dyn Machine, pose: &[f64], ) -> Option<(f64, f64)>

Half the period in profile cycles of the first shaper and of the second (0 without one) with the plan at pose: as configured, or, when the shaper follows the pose, that of the resonance the machine reports there for the first and that of its second mode (Machine::sway_modes) for the second; one the machine does not report stays as configured. None with the shaper off.

Source

pub fn shaper_span(&self, machine: &dyn Machine, pose: &[f64]) -> f64

How many profile cycles the shaped setpoint arrives after the plan with the plan at pose: the longest of the axes’ shapers; on the ramp to a changed machine’s period (shape) with the longer of the two. 0 with the shaper off.

Source

pub fn shaper_delays( &self, machine: &dyn Machine, pose: &[f64], ) -> (Vec<f64>, f64)

With the plan at pose: per axis how far the shaped setpoint lags a plan at a constant speed (the mean of the shaper’s delays, s), and how long after the plan it arrives (shaper_span, s). Zeros with the shaper off.

Trait Implementations§

Source§

impl Clone for Controller

Source§

fn clone(&self) -> Controller

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'de> Deserialize<'de> for Controller

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Controller

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.