Esempio n. 1
0
    def __init__(self, gpio, address=0x29, debug=False):
        # Depending on if you have an old or a new Raspberry Pi, you
        # may need to change the I2C bus.  Older Pis use SMBus 0,
        # whereas new Pis use SMBus 1.  If you see an error like:
        # 'Error accessing 0x29: Check your I2C address '
        # change the SMBus number in the initializer below!

        # setup i2c bus and SFR address
        self.i2c = smbus.SMBus(2)
        self.address = 0x29
        self.wanted_address = address
        self.gpio = gpio
        self.debug = debug

        # Module identification
        self.idModel = 0x00
        self.idModelRevMajor = 0x00
        self.idModelRevMinor = 0x00
        self.idModuleRevMajor = 0x00
        self.idModuleRevMinor = 0x00
        self.idDate = 0x00
        self.idTime = 0x00

        GPIO.setup(self.gpio, GPIO.OUT)
        self.deactivate()  # Must be started turned off
Esempio n. 2
0
 def __init__(self, gpio=params.START_STOP_BUTTON_PIN, from_ros=False):
     '''
     Init routine
     '''
     self.from_ros = from_ros
     if self.from_ros:
         self.activated = False
         rospy.Subscriber("button", String, self.callback)
     else:
         self.gpio = gpio
         GPIO.setup(self.gpio, GPIO.IN)
Esempio n. 3
0
    def activate(self):
        GPIO.output(self.gpio, GPIO.HIGH)
        if self.get_register(self.__VL6180X_SYSTEM_FRESH_OUT_OF_RESET) == 1:
            print("ToF sensor is ready.")
            self.ready = True
        else:
            print("ToF sensor reset failure.")
            self.ready = False

        # Required by datasheet
        # http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00122600.pdf
        self.set_register(0x0207, 0x01)
        self.set_register(0x0208, 0x01)
        self.set_register(0x0096, 0x00)
        self.set_register(0x0097, 0xfd)
        self.set_register(0x00e3, 0x00)
        self.set_register(0x00e4, 0x04)
        self.set_register(0x00e5, 0x02)
        self.set_register(0x00e6, 0x01)
        self.set_register(0x00e7, 0x03)
        self.set_register(0x00f5, 0x02)
        self.set_register(0x00d9, 0x05)
        self.set_register(0x00db, 0xce)
        self.set_register(0x00dc, 0x03)
        self.set_register(0x00dd, 0xf8)
        self.set_register(0x009f, 0x00)
        self.set_register(0x00a3, 0x3c)
        self.set_register(0x00b7, 0x00)
        self.set_register(0x00bb, 0x3c)
        self.set_register(0x00b2, 0x09)
        self.set_register(0x00ca, 0x09)
        self.set_register(0x0198, 0x01)
        self.set_register(0x01b0, 0x17)
        self.set_register(0x01ad, 0x00)
        self.set_register(0x00ff, 0x05)
        self.set_register(0x0100, 0x05)
        self.set_register(0x0199, 0x05)
        self.set_register(0x01a6, 0x1b)
        self.set_register(0x01ac, 0x3e)
        self.set_register(0x01a7, 0x1f)
        self.set_register(0x0030, 0x00)

        # Change address if requested
        if self.wanted_address != 0x29:
            self.change_address(0x29, self.wanted_address)

        self.get_distance(
        )  # This is needed because sometimes the very first measurement is 0
Esempio n. 4
0
 def read_raw(self):
     '''
     Read all the sensor values
     '''
     if not self.from_ros:
         return GPIO.input(self.gpio)
     else:
         return self.activated
Esempio n. 5
0
    def setSpeedRight(self, power, coeff=0):
        if (power < 0):
            GPIO.output(self.pins['dir_fr'], GPIO.LOW)
            GPIO.output(self.pins['dir_rr'], GPIO.LOW)
        else:
            GPIO.output(self.pins['dir_fr'], GPIO.HIGH)
            GPIO.output(self.pins['dir_rr'], GPIO.HIGH)

        power = abs(power)
        if power > 100:
            power = 100
        if power + coeff > 100:
            coeff = 100
        elif power + coeff < 0:
            coeff = 0
        else:
            coeff = power + coeff

        PWM.start(self.pins['fr'], power, 25000)
        PWM.start(self.pins['rr'], coeff, 25000)
        self.actual_r = power
Esempio n. 6
0
    def __init__(self, pins=params.motors_pins):
        """
        pins are provided by a dictionary formatted like:
        {
            'fr':fr,
            'fl':fl,
            'rr':rr,
            'rl':rl,
            'dir_fr':dir_fr,
            'dir_fl':dir_fl,
            'dir_rr':dir_rr,
            'dir_rl':dir_rl
        }
        """
        GPIO.setup(pins['dir_fr'], GPIO.OUT)
        GPIO.setup(pins['dir_fl'], GPIO.OUT)
        GPIO.setup(pins['dir_rr'], GPIO.OUT)
        GPIO.setup(pins['dir_rl'], GPIO.OUT)

        self.pins = pins
        self.actual_l = 0
        self.actual_r = 0
Esempio n. 7
0
    def activate(self):
        GPIO.output(self.gpio, GPIO.HIGH)

        # Change address if requested
        if self.wanted_address != 0x29:
            self.change_address(0x29, self.wanted_address)
Esempio n. 8
0
 def deactivate(self):
     GPIO.output(self.gpio, GPIO.LOW)
import sys
import os
import time
import utils.GPIO as GPIO
import subprocess
import signal
import actuators.motors as motors
import config.params as params

if __name__ == '__main__':
    pin = "gpio65"
    #os.system("sh /root/rsm-2017-ga/start.sh")
    #os.system("sh /root/rsm-2017-ga/start_routine.sh")
    os_command = "python /root/rsm-2017-ga/main.py"

    GPIO.setup(pin, GPIO.IN)
    m = motors.Motor(params.motors_pins)
    m.stop()
    pro = subprocess.Popen(os_command,
                           stdout=open(os.devnull, 'wb'),
                           shell=True,
                           preexec_fn=os.setsid)
    print(os.getpgid(pro.pid))
    print(pro.pid)
    while True:
        if GPIO.input(pin) == True:
            started_pressing = time.time()
            while GPIO.input(pin) == True:
                pass
            pressed_time = time.time() - started_pressing
            print("OMFG, you pressed da button!")
Esempio n. 10
0
 def __init__(self, pins=params.touch_pins):
     self.pins = pins
     GPIO.setup(self.pins['E'], 'in')
     GPIO.setup(self.pins['O'], 'in')
Esempio n. 11
0
 def read(self, dir):
     return GPIO.input(self.pins[dir])
Esempio n. 12
0
 def __init__(self, pin= params.LED_PIN):
     self.pin = pin
     GPIO.setup(self.pin, GPIO.OUT)
     GPIO.output(self.pin, GPIO.LOW)
Esempio n. 13
0
 def off(self):
     '''
     Turn off the Led
     '''
     GPIO.output(self.pin, GPIO.LOW)
Esempio n. 14
0
 def on(self):
     '''
     Turn on the Led
     '''
     GPIO.output(self.pin, GPIO.HIGH)