metered_motors – adds encoder feedback to the original botcore.Motors class

Module metered_motors

Contains the MeteredMotors class which adds encoder feedback to the original botcore.Motors class. This is a building block towards being able to tell how fast you are going, or how far you have gone.

class metered_motors.MeteredMotors(motors, leds)[source]

A wrapper class for the existing Motor class that adds support for making use of the two optical encoders too. Notice that it mimics the API of the botcore.Motors class, and then extends it.

enable(do_enable)[source]

Enabling the motors allows them to move, disabling them stops them from spinning.

Parameters

do_enable (bool) – true to enable, false to disable

get_and_reset_ticks()[source]

Get the current tick counts as a (left, right) tuple, and restart the counters.

get_ticks()[source]

Get the current tick counts as a (left, right) tuple.

Does not reset the tick counters.

left_encoder_handler(timer_is_unused)[source]

Interrupt handler for the left encoder wheel. You don’t call this.

right_encoder_handler(timer_is_unused)[source]

Interrupt handler for the right encoder wheel. You don’t call this.

run(num, pwr)[source]

Run the specified motor at the specified power.

Parameters
  • num (int) – which motor (0 = LEFT, 1 = RIGHT)

  • pwr (int) – power level as a percentage, -100 to 0 to +100

Power levels are negative for reverse (clockwise) motion. Power levels are positive for forward (counter-clockwise) motion. A power level of 0 means stop.

Download Source