Struct ev3dev_lang_rust::motors::LargeMotor [−][src]
pub struct LargeMotor { /* fields omitted */ }
Expand description
EV3/NXT large servo motor
Implementations
Try to get a Self
on the given port. Returns None
if port is not used or another device is connected.
Try to find a Self
. Only returns a motor if their is exactly one connected, Error::NotFound
otherwise.
Causes the motor to run until another command is sent.
Runs the motor to an absolute position specified by position_sp
and then stops the motor using the command specified in stop_action
.
Runs the motor to a position relative to the current position value.
The new position will be current position
+ position_sp
.
When the new position is reached, the motor will stop using the command specified by stop_action
.
Run the motor for the amount of time specified in time_sp
and then stops the motor using the command specified by stop_action
.
Runs the motor using the duty cycle specified by duty_cycle_sp
.
Unlike other run commands, changing duty_cycle_sp
while running will take effect immediately.
Stop any of the run commands before they are complete using the command specified by stop_action
.
Resets all of the motor parameter attributes to their default values. This will also have the effect of stopping the motor.
A positive duty cycle will cause the motor to rotate clockwise.
A positive duty cycle will cause the motor to rotate counter-clockwise.
Power is being sent to the motor.
The motor is ramping up or down and has not yet reached a pub constant output level.
The motor is not turning, but rather attempting to hold a fixed position.
The motor is turning as fast as possible, but cannot reach its speed_sp
.
The motor is trying to run but is not turning at all.
Removes power from the motor. The motor will freely coast to a stop.
Removes power from the motor and creates a passive electrical load. This is usually done by shorting the motor terminals together. This load will absorb the energy from the rotation of the motors and cause the motor to stop more quickly than coasting.
Causes the motor to actively try to hold the current position. If an external force tries to turn the motor, the motor will “push back” to maintain its position.
Returns the number of tacho counts in one rotation of the motor.
Tacho counts are used by the position and speed attributes, so you can use this value to convert from rotations or degrees to tacho counts. (rotation motors only)
Examples
use ev3dev_lang_rust::motors::LargeMotor;
// Init a tacho motor.
let motor = LargeMotor::find()?;
// Get position and count_per_rot as f32.
let position = motor.get_position()? as f32;
let count_per_rot = motor.get_count_per_rot()? as f32;
// Calculate the rotation count.
let rotations = position / count_per_rot;
println!("The motor did {:.2} rotations", rotations);
Returns the number of tacho counts in one meter of travel of the motor.
Tacho counts are used by the position and speed attributes, so you can use this value to convert from distance to tacho counts. (linear motors only)
Returns the number of tacho counts in the full travel of the motor.
When combined with the count_per_m atribute, you can use this value to calculate the maximum travel distance of the motor. (linear motors only)
Returns the current duty cycle of the motor. Units are percent.
Values are -100 to 100.
Examples
use ev3dev_lang_rust::motors::LargeMotor;
use std::thread;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
// Set the motor command `run-direct` to start rotation.
motor.run_direct()?;
// Rotate motor forward and wait 5 seconds.
motor.set_duty_cycle_sp(50)?;
thread::sleep(Duration::from_secs(5));
assert_eq!(motor.get_duty_cycle()?, 50);
Returns the current duty cycle setpoint of the motor.
Units are in percent. Valid values are -100 to 100. A negative value causes the motor to rotate in reverse.
Examples
use ev3dev_lang_rust::motors::LargeMotor;
use std::thread;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
// Rotate motor forward and wait 5 seconds.
motor.set_duty_cycle_sp(50)?;
thread::sleep(Duration::from_secs(5));
assert_eq!(motor.get_duty_cycle()?, 50);
Sets the duty cycle setpoint of the motor.
Units are in percent. Valid values are -100 to 100. A negative value causes the motor to rotate in reverse.
Examples
use ev3dev_lang_rust::motors::LargeMotor;
use std::thread;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
// Set the motor command `run-direct` to start rotation.
motor.run_direct()?;
// Rotate motor forward and wait 5 seconds.
motor.set_duty_cycle_sp(50)?;
thread::sleep(Duration::from_secs(5));
// Rotate motor backward and wait 5 seconds.
motor.set_duty_cycle_sp(-50)?;
thread::sleep(Duration::from_secs(5));
Returns the current polarity of the motor.
Sets the polarity of the motor.
Returns the current position of the motor in pulses of the rotary encoder.
When the motor rotates clockwise, the position will increase. Likewise, rotating counter-clockwise causes the position to decrease. The range is -2,147,483,648 and +2,147,483,647 tachometer counts (32-bit signed integer)
Examples
use ev3dev_lang_rust::motors::LargeMotor;
// Init a tacho motor.
let motor = LargeMotor::find()?;
// Get position and count_per_rot as f32.
let position = motor.get_position()? as f32;
let count_per_rot = motor.get_count_per_rot()? as f32;
// Calculate the rotation count.
let rotations: f32 = position / count_per_rot;
println!("The motor did {:.2} rotations", rotations);
Sets the current position of the motor in pulses of the rotary encoder.
When the motor rotates clockwise, the position will increase. Likewise, rotating counter-clockwise causes the position to decrease. The range is -2,147,483,648 and +2,147,483,647 tachometer counts (32-bit signed integer)
Examples
use ev3dev_lang_rust::motors::LargeMotor;
// Init a tacho motor.
let motor = LargeMotor::find()?;
motor.set_position(0)?;
let position = motor.get_position()?;
// If the motor is not moving, the position value
// should not change between set and get operation.
assert_eq!(position, 0);
Returns the proportional pub constant for the position PID.
Sets the proportional pub constant for the position PID.
Returns the integral pub constant for the position PID.
Sets the integral pub constant for the position PID.
Returns the derivative pub constant for the position PID.
Sets the derivative pub constant for the position PID.
Returns the maximum value that is accepted by the speed_sp
attribute.
This value is the speed of the motor at 9V with no load. Note: The actual maximum obtainable speed will be less than this and will depend on battery voltage and mechanical load on the motor.
Returns the current target position for the run-to-abs-pos
and run-to-rel-pos
commands.
Units are in tacho counts.
You can use the value returned by counts_per_rot
to convert tacho counts to/from rotations or degrees.
The range is -2,147,483,648 and +2,147,483,647 tachometer counts (32-bit signed integer).
Sets the target position for the run-to-abs-pos
and run-to-rel-pos
commands.
Units are in tacho counts.
You can use the value returned by counts_per_rot
to convert tacho counts to/from rotations or degrees.
The range is -2,147,483,648 and +2,147,483,647 tachometer counts (32-bit signed integer).
Examples
use ev3dev_lang_rust::motors::LargeMotor;
use std::thread;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
// Save the current position.
let old_position = motor.get_position()?;
// Rotate by 100 ticks
let position = motor.set_position_sp(100)?;
motor.run_to_rel_pos(None)?;
// Wait till rotation is finished.
motor.wait_until_not_moving(None);
// The new position should be 100 ticks larger.
let new_position = motor.get_position()?;
assert_eq!(old_position + 100, new_position);
Returns the current motor speed in tacho counts per second.
Note, this is not necessarily degrees (although it is for LEGO motors).
Use the count_per_rot
attribute to convert this value to RPM or deg/sec.
Returns the target speed in tacho counts per second used for all run-* commands except run-direct.
A negative value causes the motor to rotate in reverse
with the exception of run-to-*-pos commands where the sign is ignored.
Use the count_per_rot
attribute to convert RPM or deg/sec to tacho counts per second.
Use the count_per_m
attribute to convert m/s to tacho counts per second.
Sets the target speed in tacho counts per second used for all run-* commands except run-direct.
A negative value causes the motor to rotate in reverse
with the exception of run-to-*-pos commands where the sign is ignored.
Use the count_per_rot
attribute to convert RPM or deg/sec to tacho counts per second.
Use the count_per_m
attribute to convert m/s to tacho counts per second.
Returns the current ramp up setpoint.
Units are in milliseconds and must be positive. When set to a non-zero value,
the motor speed will increase from 0 to 100% of max_speed
over the span of this setpoint.
The actual ramp time is the ratio of the difference between the speed_sp
and the current speed and max_speed multiplied by ramp_up_sp. Values must not be negative.
Sets the ramp up setpoint.
Units are in milliseconds and must be positive. When set to a non-zero value,
the motor speed will increase from 0 to 100% of max_speed
over the span of this setpoint.
The actual ramp time is the ratio of the difference between the speed_sp
and the current speed and max_speed multiplied by ramp_up_sp. Values must not be negative.
Returns the current ramp down setpoint.
Units are in milliseconds and must be positive. When set to a non-zero value,
the motor speed will decrease from 100% down to 0 of max_speed
over the span of this setpoint.
The actual ramp time is the ratio of the difference between the speed_sp
and the current speed and 0 multiplied by ramp_down_sp. Values must not be negative.
Sets the ramp down setpoint.
Units are in milliseconds and must be positive. When set to a non-zero value,
the motor speed will decrease from 100% down to 0 of max_speed
over the span of this setpoint.
The actual ramp time is the ratio of the difference between the speed_sp
and the current speed and 0 multiplied by ramp_down_sp. Values must not be negative.
Returns the proportional pub constant for the speed regulation PID.
Sets the proportional pub constant for the speed regulation PID.
Returns the integral pub constant for the speed regulation PID.
Sets the integral pub constant for the speed regulation PID.
Returns the derivative pub constant for the speed regulation PID.
Sets the derivative pub constant for the speed regulation PID.
Returns the current stop action.
The value determines the motors behavior when command is set to stop.
Sets the stop action.
The value determines the motors behavior when command is set to stop.
Returns a list of stop actions supported by the motor controller.
Returns the current amount of time the motor will run when using the run-timed command.
Units are in milliseconds. Values must not be negative.
Sets the amount of time the motor will run when using the run-timed command.
Units are in milliseconds. Values must not be negative.
Runs the motor using the duty cycle specified by duty_cycle_sp
.
Unlike other run commands, changing duty_cycle_sp
while running will take effect immediately.
Causes the motor to run until another command is sent.
Runs the motor to an absolute position specified by position_sp
and then stops the motor using the command specified in stop_action
.
Runs the motor to a position relative to the current position value.
The new position will be current position
+ position_sp
.
When the new position is reached, the motor will stop using the command specified by stop_action
.
Run the motor for the amount of time specified in time_sp
and then stops the motor using the command specified by stop_action
.
Stop any of the run commands before they are complete using the command specified by stop_action
.
Resets all of the motor parameter attributes to their default values. This will also have the effect of stopping the motor.
Power is being sent to the motor.
The motor is ramping up or down and has not yet reached a pub constant output level.
The motor is not turning, but rather attempting to hold a fixed position.
The motor is turning as fast as possible, but cannot reach its speed_sp
.
The motor is trying to run but is not turning at all.
Wait until condition cond
returns true or the timeout
is reached.
The condition is checked when to the state
attribute has changed.
If the timeout
is None
it will wait an infinite time.
Examples
use ev3dev_lang_rust::motors::LargeMotor;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
motor.run_timed(Some(Duration::from_secs(5)))?;
let cond = || {
motor.get_state()
.unwrap_or_else(|_| vec![])
.iter()
.all(|s| s != LargeMotor::STATE_RUNNING)
};
motor.wait(cond, None);
println!("Motor has stopped!");
Wait while the state
is in the vector self.get_state()
or the timeout
is reached.
If the timeout
is None
it will wait an infinite time.
Example
use ev3dev_lang_rust::motors::LargeMotor;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
motor.run_timed(Some(Duration::from_secs(5)))?;
motor.wait_while(LargeMotor::STATE_RUNNING, None);
println!("Motor has stopped!");
Wait until the state
is in the vector self.get_state()
or the timeout
is reached.
If the timeout
is None
it will wait an infinite time.
Example
use ev3dev_lang_rust::motors::LargeMotor;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
motor.run_timed(Some(Duration::from_secs(5)))?;
motor.wait_until(LargeMotor::STATE_RUNNING, None);
println!("Motor has started!");
Wait until the motor is not moving or the timeout is reached.
This is euqal to wait_while(STATE_RUNNING, timeout)
.
If the timeout
is None
it will wait an infinite time.
Example
use ev3dev_lang_rust::motors::LargeMotor;
use std::time::Duration;
// Init a tacho motor.
let motor = LargeMotor::find()?;
motor.run_timed(Some(Duration::from_secs(5)))?;
motor.wait_until_not_moving(None);
println!("Motor has stopped!");
Trait Implementations
Returns the attribute wrapper for an attribute name.
Returns the name of the port that the motor is connected to.
Sends a command to the device controller.
Returns a space separated list of commands that are supported by the device controller.
Returns the name of the driver that provides this device.
Performs the conversion.
Auto Trait Implementations
impl !RefUnwindSafe for LargeMotor
impl Send for LargeMotor
impl !Sync for LargeMotor
impl Unpin for LargeMotor
impl UnwindSafe for LargeMotor
Blanket Implementations
Mutably borrows from an owned value. Read more