7 LEGO
mishi edited this page 2020-10-18 14:42:46 +02:00

LEGO

Description

The LEGO is not yet defined but is based on up to for DC motors controlled via the RPi's hardware PWM. The RPi interacts with H-bridges such as L293D instead of the classic relay board. Up to 8 pins are used 4 with the hardware PWM and 4 for the direction selection.

Network location

Workflows

  • accelerate: Motor speed is increased by 20%. The speed can't go above 100%.
  • decelerate: Motor speed is decreased by 20%. If the speed goes negative, the direction is reversed. The speed can't get lower than -100%.
  • stop: Motor speed is set to 0%.
  • full_forward: Motor speed is set to 100%
  • full_backward: Motor speed is set to -100%. The direction is reversed.

Raspberry Pi pinout:

RPi Pin RPi Name Destination Wire Function
1 3V3 H bridge VCC brown
6 Ground H bridge Gnd black
12 GPIO18 H bridge IN 1+ red PWM motor 1
16 GPIO23 H bridge IN 1- orange DIR motor 1
32 GPIO12 H bridge IN 2+ PWM 2
GPIO H bridge IN 2- DIR 2
33 GPIO13 H bridge IN 3+ PWM 3
GPIO H bridge IN 3- DIR 3
35 GPIO19 H bridge IN 4+ PWM 4
GPIO H bridge IN 4- DIR 4

TODO

  • Expand implementation to four motors. Today, only PWM 1 and DIR1 are supported. PWM 1 pin mapping is hardcoded as well.
  • Make the transitions of the motor speed smoother by changing the speed in 20% steps. Today, it can change from -100 to +100% which creates are large ruck.
  • Accelerate the handover of speed changes. Today, the new speed is hander to the PWM control task which applies the new value every 100ms.
  • Also, the speed changes are applied with a HTTP GET which requires a page to be returned. With a PUSH it might be quicker. Same as for the button toggles. This would require a custom control page for the motor controls like the system page. How about a slider for the speed? We need a generic route for setting the motor speed. DONE
  • PWM frequency should be made a parameter.
  • The speed step size (today 20%) should be made a parameter.