The Drive Module

Added in version 0.2

A helper class designed for L298N motor controller.

class crh_botnet.drive.HBridgeDrive(left_ground, left_power, left_enable, right_ground, right_power, right_enable, reverse_left=False, reverse_right=False)
__init__(left_ground, left_power, left_enable, right_ground, right_power, right_enable, reverse_left=False, reverse_right=False)

All pin numbers here are GPIO number, not the actual pin number.

Parameters
  • left_ground (int) – The GND pin for the left motor

  • left_power (int) – The VCC pin for the left motor

  • left_enable (int) – The EN pin for the left motor

  • right_ground (int) – The GND pin for the right motor

  • right_power (int) – The VCC pin for the right motor

  • right_enable (int) – The EN pin for the right motor

  • reverse_left (bool) – Reverse the direction of left motor. Default to False.

  • reverse_right (bool) – Reverse the direction of right motor. Default to False.

__call__(left, right)

Convenience function for drive()

Parameters
  • left (float) – Power to the left motor, in range [-1,1]

  • right (float) – Power to the right motor, in range [-1,1]

Returns

None

drive(power_left, power_right)

Power left and power right to the motor.

Parameters
  • power_left (float) – Power to the left motor, in range [-1,1]

  • power_right (float) – Power to the right motor, in range [-1,1]

Returns

None

stop()

A convenient function to Stop both motors. Equivalent to drive(0,0)

Returns

None

An example can be found at HBridge Drive.