Hi everyone,
I purchased the Pololu Dual G2 High-Power Motor Driver 24v14 for Raspberry Pi and used the python examples were provided. Everything works fine….The one issue I’m having is everything is in max speed and runs for few seconds so my questions are
1- How to control the speed on this shield? Like reduce the speed to 50%
2- I defined left and right but it will run in circles and for obvious reasons of course. It will run for a long period of time. How to make it runs for short time?
I attached the manufacturer example and below is my right/left function… I would really appreciate any help
def Right():
for s in test_forward_speeds:
motors.motor1.setSpeed(s)
Motor_Controlling.raiseIfFault()
timer_thread = multiprocessing.Process(target=Motor_Controlling.timer)
timer_thread.start()
if not timer_thread.is_alive():
motors.forceStop()
Motor_Controlling.forward()
and the motor example
from __future__ import print_function
import time
from dual_g2_hpmd_rpi import motors, MAX_SPEED
# Define a custom exception to raise if a fault is detected.
class DriverFault(Exception):
def __init__(self, driver_num):
self.driver_num = driver_num
def raiseIfFault():
if motors.motor1.getFault():
raise DriverFault(1)
if motors.motor2.getFault():
raise DriverFault(2)
# Set up sequences of motor speeds.
test_forward_speeds = list(range(0, MAX_SPEED, 1)) + \
[MAX_SPEED] * 200 + list(range(MAX_SPEED, 0, -1)) + [0]
test_reverse_speeds = list(range(0, -MAX_SPEED, -1)) + \
[-MAX_SPEED] * 200 + list(range(-MAX_SPEED, 0, 1)) + [0]
try:
motors.setSpeeds(0, 0)
print("Motor 1 forward")
for s in test_forward_speeds:
motors.motor1.setSpeed(s)
raiseIfFault()
time.sleep(0.002)
print("Motor 1 reverse")
for s in test_reverse_speeds:
motors.motor1.setSpeed(s)
raiseIfFault()
time.sleep(0.002)
# Disable the drivers for half a second.
motors.disable()
time.sleep(0.5)
motors.enable()
print("Motor 2 forward")
for s in test_forward_speeds:
motors.motor2.setSpeed(s)
raiseIfFault()
time.sleep(0.002)
print("Motor 2 reverse")
for s in test_reverse_speeds:
motors.motor2.setSpeed(s)
raiseIfFault()
time.sleep(0.002)
except DriverFault as e:
print("Driver %s fault!" % e.driver_num)
finally:
# Stop the motors, even if there is an exception
# or the user presses Ctrl+C to kill the process.
motors.forceStop()
Motor_example.py (1.6 KB)