Hello,
I am building a robot with 4 separate DC motors(from RoboShop-- RB-Dfr-444) with Raspberry Pi 3+, a Geekworm Full Function Motor Hat (TB-418460), a power relay HAT (12v) and using Python as the software.
This robot also has Mecanum wheels so therefore I want to control any combination of 1 to 4 motors’ movement via the software.
I have made this work successfully but have an intermittent lack of motion of motors 3 & 4 in some commands as indicated by the comments. Motors 1 & 2 work in all regimes. Motors 3 & 4 work in some lines of code and do not work in other lines. Code wording is exactly the same and all connections have be checked and are secure. I have replaced the motorHAT with a new unit. Still having same issues.
Could someone look at the file below (especially the comments) and see if any errors are spotted. This is definitely and programming software issue and not mechanical/electrical.
Thanks,
Gary
#This program test the mecanum wheels in all directions!
from Raspi_MotorHAT import Raspi_MotorHAT
import smbus
import time
import atexit
DEVICE_BUS = 1 **#this is a relay HAT to power motors**
DEVICE_ADDR = 0x10
bus = smbus.SMBus(DEVICE_BUS)
bus.write_byte_data(0x10, 1, 0xFF)
mh = Raspi_MotorHAT(addr=0x6f) **#this is the motor controlling HAT**
m1 = mh.getMotor(1)
m2 = mh.getMotor(2)
m3 = mh.getMotor(3)
m4 = mh.getMotor(4)
def turn_off_motors():
m1.run(Raspi_MotorHAT.RELEASE)
m2.run(Raspi_MotorHAT.RELEASE)
m3.run(Raspi_MotorHAT.RELEASE)
m4.run(Raspi_MotorHAT.RELEASE)
atexit.register(turn_off_motors)
m1.setSpeed(50)
m2.setSpeed(50)
m3.setSpeed(50)
m4.setSpeed(50)
#straight forward
print("straight forward")
m1.run(Raspi_MotorHAT.FORWARD) **#all wheels function normally on this command**
m2.run(Raspi_MotorHAT.FORWARD)
m3.run(Raspi_MotorHAT.FORWARD)
m4.run(Raspi_MotorHAT.FORWARD)
time.sleep(4)
turn_off_motors()
time.sleep(1)
#turn left
print("turn left")
time.sleep(2)
m2.run(Raspi_MotorHAT.FORWARD) **# wheel functions normally on this command**
m4.run(Raspi_MotorHAT.FORWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#turn right
print("turn right")
time.sleep(2)
m1.run(Raspi_MotorHAT.FORWARD) **# wheel functions normally on this command**
m3.run(Raspi_MotorHAT.FORWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#horizontal left
print("horizontal left")
time.sleep(2)
m1.run(Raspi_MotorHAT.BACKWARD) **# wheel functions normally on this command**
m2.run(Raspi_MotorHAT.FORWARD) **# wheel functions normally on this command**
m3.run(Raspi_MotorHAT.BACKWARD) **# wheel does not function on this command**
m4.run(Raspi_MotorHAT.FORWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#spin left
print("spin left")
time.sleep(2)
m1.run(Raspi_MotorHAT.BACKWARD) **# wheel functions normally on this command**
m2.run(Raspi_MotorHAT.FORWARD) **# wheel functions normally on this command**
m3.run(Raspi_MotorHAT.FORWARD) **# wheel does not function on this command**
m4.run(Raspi_MotorHAT.BACKWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#spin right
print("spin right")
time.sleep(4)
m1.run(Raspi_MotorHAT.FORWARD) **# wheel functions normally on this command**
m2.run(Raspi_MotorHAT.BACKWARD) **# wheel functions normally on this command**
m3.run(Raspi_MotorHAT.BACKWARD) **# wheel does not function on this command**
m4.run(Raspi_MotorHAT.FORWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#horizontal right
print("horizontal right")
time.sleep(4)
m1.run(Raspi_MotorHAT.FORWARD) **# wheel functions normally on this command**
m2.run(Raspi_MotorHAT.BACKWARD) **# wheel functions normally on this command**
m3.run(Raspi_MotorHAT.FORWARD) **# wheel does not function on this command**
m4.run(Raspi_MotorHAT.BACKWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#back left
print("1 & 3 back left")
time.sleep(4)
m1.run(Raspi_MotorHAT.BACKWARD) **# wheel functions normally on this command**
m3.run(Raspi_MotorHAT.BACKWARD) **# wheel does not function on this command**
time.sleep(2)
turn_off_motors()
#straight backwards
print("straight backwards")
time.sleep(2)
m1.run(Raspi_MotorHAT.BACKWARD) **#all wheels function normally on this command**
m2.run(Raspi_MotorHAT.BACKWARD)
m3.run(Raspi_MotorHAT.BACKWARD)
m4.run(Raspi_MotorHAT.BACKWARD)
time.sleep(2)
turn_off_motors()
time.sleep(1)
bus.write_byte_data(0x10, 1, 0x00)