Change IR Sensor, fix motor direction
This commit is contained in:
parent
77c2354c00
commit
a544133e92
2 changed files with 28 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
import RPi.GPIO as GPIO
|
import pigpio
|
||||||
|
|
||||||
from compLib.ADC import ADC
|
from compLib.ADC import ADC
|
||||||
from compLib.LogstashLogging import Logging
|
from compLib.LogstashLogging import Logging
|
||||||
|
@ -15,12 +15,26 @@ BOTTOM_RIGHT_PIN = 23
|
||||||
|
|
||||||
adc = ADC()
|
adc = ADC()
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
# GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
GPIO.setup(BOTTOM_LEFT_PIN, GPIO.IN)
|
GPIO = pigpio.pi()
|
||||||
GPIO.setup(BOTTOM_MIDDLE_PIN, GPIO.IN)
|
|
||||||
GPIO.setup(BOTTOM_RIGHT_PIN, GPIO.IN)
|
|
||||||
|
|
||||||
|
GPIO.set_mode(BOTTOM_LEFT_PIN, pigpio.INPUT)
|
||||||
|
GPIO.set_mode(BOTTOM_MIDDLE_PIN, pigpio.INPUT)
|
||||||
|
GPIO.set_mode(BOTTOM_RIGHT_PIN, pigpio.INPUT)
|
||||||
|
|
||||||
|
states = {
|
||||||
|
str(BOTTOM_LEFT_PIN): 0,
|
||||||
|
str(BOTTOM_MIDDLE_PIN): 0,
|
||||||
|
str(BOTTOM_RIGHT_PIN): 0}
|
||||||
|
|
||||||
|
def gpio_callback(gpio, level, tick):
|
||||||
|
states[str(gpio)] = level
|
||||||
|
# print(gpio, level, tick)
|
||||||
|
|
||||||
|
GPIO.callback(BOTTOM_LEFT_PIN, pigpio.EITHER_EDGE, gpio_callback)
|
||||||
|
GPIO.callback(BOTTOM_MIDDLE_PIN, pigpio.EITHER_EDGE, gpio_callback)
|
||||||
|
GPIO.callback(BOTTOM_RIGHT_PIN, pigpio.EITHER_EDGE, gpio_callback)
|
||||||
|
|
||||||
class IRSensor(object):
|
class IRSensor(object):
|
||||||
"""Access the different IR Sensors at top / bottom of the robot
|
"""Access the different IR Sensors at top / bottom of the robot
|
||||||
|
@ -53,7 +67,8 @@ class IRSensor(object):
|
||||||
:return: True, if sensor detects IR signals
|
:return: True, if sensor detects IR signals
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return GPIO.input(BOTTOM_LEFT_PIN)
|
return states[str(BOTTOM_LEFT_PIN)]
|
||||||
|
# return GPIO.read(BOTTOM_LEFT_PIN)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bottom_middle() -> bool:
|
def bottom_middle() -> bool:
|
||||||
|
@ -62,7 +77,8 @@ class IRSensor(object):
|
||||||
:return: True, if sensor detects IR signals
|
:return: True, if sensor detects IR signals
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return GPIO.input(BOTTOM_MIDDLE_PIN)
|
return states[str(BOTTOM_MIDDLE_PIN)]
|
||||||
|
# return GPIO.read(BOTTOM_MIDDLE_PIN)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def bottom_right() -> bool:
|
def bottom_right() -> bool:
|
||||||
|
@ -71,4 +87,5 @@ class IRSensor(object):
|
||||||
:return: True, if sensor detects IR signals
|
:return: True, if sensor detects IR signals
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
return GPIO.input(BOTTOM_RIGHT_PIN)
|
return states[str(BOTTOM_RIGHT_PIN)]
|
||||||
|
# return GPIO.read(BOTTOM_RIGHT_PIN)
|
||||||
|
|
|
@ -39,11 +39,11 @@ class Motor(object):
|
||||||
adjusted_speed = int(min(max(0, percent), 100) * MOTOR_PERCENTAGE_MULT)
|
adjusted_speed = int(min(max(0, percent), 100) * MOTOR_PERCENTAGE_MULT)
|
||||||
|
|
||||||
if forward:
|
if forward:
|
||||||
pwm.setMotorPwm(port * 2, 0)
|
|
||||||
pwm.setMotorPwm(port * 2 + 1, adjusted_speed)
|
|
||||||
else:
|
|
||||||
pwm.setMotorPwm(port * 2, adjusted_speed)
|
pwm.setMotorPwm(port * 2, adjusted_speed)
|
||||||
pwm.setMotorPwm(port * 2 + 1, 0)
|
pwm.setMotorPwm(port * 2 + 1, 0)
|
||||||
|
else:
|
||||||
|
pwm.setMotorPwm(port * 2, 0)
|
||||||
|
pwm.setMotorPwm(port * 2 + 1, adjusted_speed)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def all_off():
|
def all_off():
|
||||||
|
|
Reference in a new issue