ServoKit.ServoUtil (servo_kit v0.0.8) View Source
A collection of pure functions that are used for the servo abstractions.
Link to this section Summary
Functions
Calculates duty cycle in percent from an angle in degrees.
Calculates duty cycle in percent from a throttle value between -1.0 (full speed reverse) and 1.0 (full speed forward) .
Adjusts the duty cycle range based on duty_cycle_mid
so that the servo stops at the throttle zero.
Maps a given value in one range to another range.
Link to this section Functions
Calculates duty cycle in percent from an angle in degrees.
iex> ServoKit.ServoUtil.duty_cycle_from_angle(0, %{angle_max: 180, duty_cycle_minmax: {2.5, 12.5}})
2.5
iex> ServoKit.ServoUtil.duty_cycle_from_angle(90, %{angle_max: 180, duty_cycle_minmax: {2.5, 12.5}})
7.5
iex> ServoKit.ServoUtil.duty_cycle_from_angle(180, %{angle_max: 180, duty_cycle_minmax: {2.5, 12.5}})
12.5
Calculates duty cycle in percent from a throttle value between -1.0 (full speed reverse) and 1.0 (full speed forward) .
Adjusts the duty cycle range based on duty_cycle_mid
so that the servo stops at the throttle zero.
iex> ServoKit.ServoUtil.duty_cycle_from_throttle(-1.0, %{duty_cycle_minmax: {2.5, 12.5}, duty_cycle_mid: 7.5})
2.5
iex> ServoKit.ServoUtil.duty_cycle_from_throttle(0.0, %{duty_cycle_minmax: {2.5, 12.5}, duty_cycle_mid: 7.5})
7.5
iex> ServoKit.ServoUtil.duty_cycle_from_throttle(0.5, %{duty_cycle_minmax: {2.5, 12.5}, duty_cycle_mid: 7.5})
10.0
iex> ServoKit.ServoUtil.duty_cycle_from_throttle(1.0, %{duty_cycle_minmax: {2.5, 12.5}, duty_cycle_mid: 7.5})
12.5
Maps a given value in one range to another range.
iex> ServoKit.ServoUtil.map_range(25, {0, 100}, {0, 180})
45.0
iex> ServoKit.ServoUtil.map_range(50, {0, 100}, {0, 180})
90.0