Struct ServoV2Bricklet

Source
pub struct ServoV2Bricklet { /* private fields */ }
Expand description

Drives up to 10 RC Servos

Implementations§

Source§

impl ServoV2Bricklet

Source

pub const DEVICE_IDENTIFIER: u16 = 2_157u16

Source

pub const DEVICE_DISPLAY_NAME: &'static str = "Servo Bricklet 2.0"

Source

pub fn new(uid: Uid, connection: AsyncIpConnection) -> ServoV2Bricklet

Creates an object with the unique device ID uid. This object can then be used after the IP Connection ip_connection is connected.

Source

pub fn get_response_expected( &mut self, fun: ServoV2BrickletFunction, ) -> Result<bool, GetResponseExpectedError>

Returns the response expected flag for the function specified by the function ID parameter. It is true if the function is expected to send a response, false otherwise.

For getter functions this is enabled by default and cannot be disabled, because those functions will always send a response. For callback configuration functions it is enabled by default too, but can be disabled by set_response_expected. For setter functions it is disabled by default and can be enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

See set_response_expected for the list of function ID constants available for this function.

Source

pub fn set_response_expected( &mut self, fun: ServoV2BrickletFunction, response_expected: bool, ) -> Result<(), SetResponseExpectedError>

Changes the response expected flag of the function specified by the function ID parameter. This flag can only be changed for setter (default value: false) and callback configuration functions (default value: true). For getter functions it is always enabled.

Enabling the response expected flag for a setter function allows to detect timeouts and other error conditions calls of this setter as well. The device will then send a response for this purpose. If this flag is disabled for a setter function then no response is sent and errors are silently ignored, because they cannot be detected.

Source

pub fn set_response_expected_all(&mut self, response_expected: bool)

Changes the response expected flag for all setter and callback configuration functions of this device at once.

Source

pub fn get_api_version(&self) -> [u8; 3]

Returns the version of the API definition (major, minor, revision) implemented by this API bindings. This is neither the release version of this API bindings nor does it tell you anything about the represented Brick or Bricklet.

Source

pub async fn get_position_reached_callback_receiver( &mut self, ) -> impl Stream<Item = PositionReachedEvent>

This receiver is triggered when a position set by set_position is reached. If the new position matches the current position then the receiver is not triggered, because the servo didn’t move. The parameters are the servo and the position that is reached.

You can enable this receiver with set_position_reached_callback_configuration.

§Note

Since we can’t get any feedback from the servo, this only works if the velocity (see set_motion_configuration) is set smaller or equal to the maximum velocity of the servo. Otherwise the servo will lag behind the control value and the receiver will be triggered too early.

Source

pub async fn get_status(&mut self) -> Result<Status, TinkerforgeError>

Returns the status information of the Servo Bricklet 2.0.

The status includes

  • for each channel if it is enabled or disabled,
  • for each channel the current position,
  • for each channel the current velocity,
  • for each channel the current usage and
  • the input voltage.

Please note that the position and the velocity is a snapshot of the current position and velocity of the servo in motion.

Source

pub async fn set_enable( &mut self, servo_channel: u16, enable: bool, ) -> Result<(), TinkerforgeError>

Enables a servo channel (0 to 9). If a servo is enabled, the configured position, velocity, acceleration, etc. are applied immediately.

Source

pub async fn get_enabled( &mut self, servo_channel: u16, ) -> Result<bool, TinkerforgeError>

Returns true if the specified servo channel is enabled, false otherwise.

Source

pub async fn set_position( &mut self, servo_channel: u16, position: i16, ) -> Result<(), TinkerforgeError>

Sets the position in °/100 for the specified servo channel.

The default range of the position is -9000 to 9000, but it can be specified according to your servo with [set_degree].

If you want to control a linear servo or RC brushless motor controller or similar with the Servo Brick, you can also define lengths or speeds with [set_degree].

Source

pub async fn get_position( &mut self, servo_channel: u16, ) -> Result<i16, TinkerforgeError>

Returns the position of the specified servo channel as set by [set_position].

Source

pub async fn get_current_position( &mut self, servo_channel: u16, ) -> Result<i16, TinkerforgeError>

Returns the current position of the specified servo channel. This may not be the value of [set_position] if the servo is currently approaching a position goal.

Source

pub async fn get_current_velocity( &mut self, servo_channel: u16, ) -> Result<u16, TinkerforgeError>

Returns the current velocity of the specified servo channel. This may not be the velocity specified by [set_motion_configuration]. if the servo is currently approaching a velocity goal.

Source

pub async fn set_motion_configuration( &mut self, servo_channel: u16, velocity: u32, acceleration: u32, deceleration: u32, ) -> Result<(), TinkerforgeError>

Sets the maximum velocity of the specified servo channel in °/100s as well as the acceleration and deceleration in °/100s²

With a velocity of 0 °/100s the position will be set immediately (no velocity).

With an acc-/deceleration of 0 °/100s² the velocity will be set immediately (no acc-/deceleration).

Source

pub async fn get_motion_configuration( &mut self, servo_channel: u16, ) -> Result<MotionConfiguration, TinkerforgeError>

Returns the motion configuration as set by [set_motion_configuration].

Source

pub async fn set_pulse_width( &mut self, servo_channel: u16, min: u32, max: u32, ) -> Result<(), TinkerforgeError>

Sets the minimum and maximum pulse width of the specified servo channel in µs.

Usually, servos are controlled with a PWM__, whereby the length of the pulse controls the position of the servo. Every servo has different minimum and maximum pulse widths, these can be specified with this function.

If you have a datasheet for your servo that specifies the minimum and maximum pulse width, you should set the values accordingly. If your servo comes without any datasheet you have to find the values via trial and error.

Both values have a range from 1 to 65535 (unsigned 16-bit integer). The minimum must be smaller than the maximum.

The default values are 1000µs (1ms) and 2000µs (2ms) for minimum and maximum pulse width.

Source

pub async fn get_pulse_width( &mut self, servo_channel: u16, ) -> Result<PulseWidth, TinkerforgeError>

Returns the minimum and maximum pulse width for the specified servo channel as set by [set_pulse_width].

Source

pub async fn set_degree( &mut self, servo_channel: u16, min: i16, max: i16, ) -> Result<(), TinkerforgeError>

Sets the minimum and maximum degree for the specified servo channel (by default given as °/100).

This only specifies the abstract values between which the minimum and maximum pulse width is scaled. For example: If you specify a pulse width of 1000µs to 2000µs and a degree range of -90° to 90°, a call of [set_position] with 0 will result in a pulse width of 1500µs (-90° = 1000µs, 90° = 2000µs, etc.).

Possible usage:

  • The datasheet of your servo specifies a range of 200° with the middle position at 110°. In this case you can set the minimum to -9000 and the maximum to 11000.
  • You measure a range of 220° on your servo and you don’t have or need a middle position. In this case you can set the minimum to 0 and the maximum to 22000.
  • You have a linear servo with a drive length of 20cm, In this case you could set the minimum to 0 and the maximum to 20000. Now you can set the Position with [set_position] with a resolution of cm/100. Also the velocity will have a resolution of cm/100s and the acceleration will have a resolution of cm/100s².
  • You don’t care about units and just want the highest possible resolution. In this case you should set the minimum to -32767 and the maximum to 32767.
  • You have a brushless motor with a maximum speed of 10000 rpm and want to control it with a RC brushless motor controller. In this case you can set the minimum to 0 and the maximum to 10000. [set_position] now controls the rpm.

Both values have a possible range from -32767 to 32767 (signed 16-bit integer). The minimum must be smaller than the maximum.

The default values are -9000 and 9000 for the minimum and maximum degree.

Source

pub async fn get_degree( &mut self, servo_channel: u16, ) -> Result<Degree, TinkerforgeError>

Returns the minimum and maximum degree for the specified servo channel as set by [set_degree].

Source

pub async fn set_period( &mut self, servo_channel: u16, period: u32, ) -> Result<(), TinkerforgeError>

Sets the period of the specified servo channel in µs.

Usually, servos are controlled with a PWM__. Different servos expect PWMs with different periods. Most servos run well with a period of about 20ms.

If your servo comes with a datasheet that specifies a period, you should set it accordingly. If you don’t have a datasheet and you have no idea what the correct period is, the default value (19.5ms) will most likely work fine.

The minimum possible period is 1µs and the maximum is 1000000µs.

The default value is 19.5ms (19500µs).

Source

pub async fn get_period( &mut self, servo_channel: u16, ) -> Result<u32, TinkerforgeError>

Returns the period for the specified servo channel as set by [set_period].

Source

pub async fn get_servo_current( &mut self, servo_channel: u16, ) -> Result<u16, TinkerforgeError>

Returns the current consumption of the specified servo channel in mA.

Source

pub async fn set_servo_current_configuration( &mut self, servo_channel: u16, averaging_duration: u8, ) -> Result<(), TinkerforgeError>

Sets the averaging duration of the current measurement for the specified servo channel in ms.

Source

pub async fn get_servo_current_configuration( &mut self, servo_channel: u16, ) -> Result<u8, TinkerforgeError>

Returns the servo current configuration for the specified servo channel as set by [set_servo_current_configuration].

Source

pub async fn set_input_voltage_configuration( &mut self, averaging_duration: u8, ) -> Result<(), TinkerforgeError>

Sets the averaging duration of the input voltage measurement for the specified servo channel in ms.

Source

pub async fn get_input_voltage_configuration( &mut self, ) -> Result<u8, TinkerforgeError>

Returns the input voltage configuration as set by [set_input_voltage_configuration].

Source

pub async fn get_overall_current(&mut self) -> Result<u16, TinkerforgeError>

Returns the current consumption of all servos together in mA.

Source

pub async fn get_input_voltage(&mut self) -> Result<u16, TinkerforgeError>

Returns the input voltage in mV. The input voltage is given via the black power input connector on the Servo Brick.

Source

pub async fn set_current_calibration( &mut self, offset: &[i16; 10], ) -> Result<(), TinkerforgeError>

Sets an offset value (in mA) for each channel.

Note: On delivery the Servo Bricklet 2.0 is already calibrated.

Source

pub async fn get_current_calibration( &mut self, ) -> Result<Box<[i16; 10]>, TinkerforgeError>

Returns the current calibration as set by [set_current_calibration].

Source

pub async fn set_position_reached_callback_configuration( &mut self, servo_channel: u16, enabled: bool, ) -> Result<(), TinkerforgeError>

Enable/Disable [get_position_reached_callback_receiver] receiver.

Source

pub async fn get_position_reached_callback_configuration( &mut self, servo_channel: u16, ) -> Result<bool, TinkerforgeError>

Returns the receiver configuration as set by [set_position_reached_callback_configuration].

Source

pub async fn get_spitfp_error_count( &mut self, ) -> Result<SpitfpErrorCount, TinkerforgeError>

Returns the error count for the communication between Brick and Bricklet.

The errors are divided into

  • ACK checksum errors,
  • message checksum errors,
  • framing errors and
  • overflow errors.

The errors counts are for errors that occur on the Bricklet side. All Bricks have a similar function that returns the errors on the Brick side.

Source

pub async fn set_bootloader_mode( &mut self, mode: u8, ) -> Result<u8, TinkerforgeError>

Sets the bootloader mode and returns the status after the requested mode change was instigated.

You can change from bootloader mode to firmware mode and vice versa. A change from bootloader mode to firmware mode will only take place if the entry function, device identifier and CRC are present and correct.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Associated constants:

  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
  • SERVO_V2_BRICKLET_BOOTLOADER_STATUS_OK
  • SERVO_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE
  • SERVO_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE
  • SERVO_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT
  • SERVO_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT
  • SERVO_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH
Source

pub async fn get_bootloader_mode(&mut self) -> Result<u8, TinkerforgeError>

Returns the current bootloader mode, see [set_bootloader_mode].

Associated constants:

  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT
  • SERVO_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT
Source

pub async fn set_write_firmware_pointer( &mut self, pointer: u32, ) -> Result<(), TinkerforgeError>

Sets the firmware pointer for [write_firmware]. The pointer has to be increased by chunks of size 64. The data is written to flash every 4 chunks (which equals to one page of size 256).

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Source

pub async fn write_firmware( &mut self, data: &[u8; 64], ) -> Result<u8, TinkerforgeError>

Writes 64 Bytes of firmware at the position as written by [set_write_firmware_pointer] before. The firmware is written to flash every 4 chunks.

You can only write firmware in bootloader mode.

This function is used by Brick Viewer during flashing. It should not be necessary to call it in a normal user program.

Source

pub async fn set_status_led_config( &mut self, config: u8, ) -> Result<(), TinkerforgeError>

Sets the status LED configuration. By default the LED shows communication traffic between Brick and Bricklet, it flickers once for every 10 received data packets.

You can also turn the LED permanently on/off or show a heartbeat.

If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.

Associated constants:

  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_OFF
  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_ON
  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
Source

pub async fn get_status_led_config(&mut self) -> Result<u8, TinkerforgeError>

Returns the configuration as set by [set_status_led_config]

Associated constants:

  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_OFF
  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_ON
  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT
  • SERVO_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS
Source

pub async fn get_chip_temperature(&mut self) -> Result<i16, TinkerforgeError>

Returns the temperature as measured inside the microcontroller. The value returned is not the ambient temperature!

The temperature is only proportional to the real temperature and it has bad accuracy. Practically it is only useful as an indicator for temperature changes.

Source

pub async fn reset(&mut self) -> Result<(), TinkerforgeError>

Calling this function will reset the Bricklet. All configurations will be lost.

After a reset you have to create new device objects, calling functions on the existing ones will result in undefined behavior!

Source

pub async fn write_uid(&mut self, uid: u32) -> Result<(), TinkerforgeError>

Writes a new UID into flash. If you want to set a new UID you have to decode the Base58 encoded UID string into an integer first.

We recommend that you use Brick Viewer to change the UID.

Source

pub async fn read_uid(&mut self) -> Result<u32, TinkerforgeError>

Returns the current UID as an integer. Encode as Base58 to get the usual string version.

Source

pub async fn get_identity(&mut self) -> Result<Identity, TinkerforgeError>

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ or ‘h’ (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position ‘z’.

The device identifier numbers can be found here. |device_identifier_constant|

Trait Implementations§

Source§

impl Clone for ServoV2Bricklet

Source§

fn clone(&self) -> ServoV2Bricklet

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. 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> 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.