Exemplo n.º 1
0
def main():
  arduino = Arduino()
  pid_client = PidClient()

  if(LOG):
    timestr = time.strftime("%Y%m%d-%H%M%S")
    filename = "pid_log-" + timestr + ".txt"
    file = open(filename,"w+")
    loglines = 0

  while(True):
    print("waiting for state...")
    state = arduino.waitForState() # blocking
    newControl = pid_client.determineControl(state)

    if(LOG):
      logLine = str(state) + "," + str(newControl) + "\n"
      logLine = logLine.strip("[]")
      file.write(logLine)
      loglines += 1
      if(loglines % 1000 == 0):
        print("loglines: {}".format(loglines))
        file.flush()

    arduino.accelerateMotorPower(newControl)
Exemplo n.º 2
0
 def __init__(self):
   stream = open("pid_values.yml", "r")
   pid_values = yaml.load(stream)
 
   self.thetaPid = Pid(pid_values['theta_p'], pid_values['theta_i'], pid_values['theta_d'], True)
   self.xPosPid = Pid(pid_values['xpos_p'], pid_values['xpos_i'], pid_values['xpos_d'], False)
   self.arduino = Arduino()
Exemplo n.º 3
0
    def __init__(self):
        self.state = State()
        self.arduino = Arduino()
        self.observation_space = SomeSpace(4)
        self.action_space = SomeSpace(1, 1.0, -1.0)
        self.episodeStartTime = datetime.datetime.now()
        self.arduino.resetRobot()

        # Pin Setup:
        self.buttonPin = 4
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Exemplo n.º 4
0
def main():

    if (len(sys.argv) != 2):
        print("give me a model file as argument please!")
        exit()

    modelfile = sys.argv[1]

    arduino = Arduino()
    model = load_model(modelfile)
    print("waiting for first state...")
    obs = arduino.waitForState()
    print("neat found first state!")

    while (True):
        obs = arduino.waitForState()
        foo = np.array(obs)
        bar = foo.reshape((1, -1))
        action = model.predict(bar, batch_size=1)
        action = action[0][0]
        print(action)
        arduino.updateMotorPower(action)
Exemplo n.º 5
0
import time
import pygame
import pygame.camera
from pygame.locals import *


from lib.arduino import Arduino
from auth import client, apply_access_token, get_new_mentions
from config import ARDUINO_ADDRESS, RELAY_PIN

if __name__ == '__main__':
    pygame.init()
    pygame.camera.init()
    cam = pygame.camera.Camera("/dev/video0",(640,480))

    arduino = Arduino(ARDUINO_ADDRESS)
    arduino.output([RELAY_PIN])
    apply_access_token()
    while 1:
        mentions = get_new_mentions()
        if mentions:
            for mention in mentions:
                command = mention['text'].split()[1]
                if command == u'开灯':
                    client.statuses.update.post(status=u'开灯啦!')
                    arduino.setHigh(RELAY_PIN)
                    print '开灯'
                elif command == u'关灯':
                    client.statuses.update.post(status=u'关灯啦!')
                    arduino.setLow(RELAY_PIN)
                    print '关灯'
Exemplo n.º 6
0
 def __init__(self):
     self.arduino = Arduino()
Exemplo n.º 7
0
# Main.py
# Main Loop and intitializations for running project

DATABASE_ENDPOINT = "http://projects.cse.tamu.edu/shotaehrlich/passingPythonInfo.php"  # Enter url to database endpoint here !!!!

# - - - Imports - - -

from lib.arduino import Arduino
from lib.database import Database
from lib.charecterization import Charecterization

# - - - Initialize Objects - - -

arduino = Arduino({'port':
                   '/dev/ttyACM0'})  # Change to proper port from Arduino IDE
database = Database(DATABASE_ENDPOINT)
charecterization = Charecterization(7, False)

# - - - Main Loop - - -

while True:

    # Poll the arduino for new data
    #print("hello")
    r = arduino.poll()
    #print("1hello")

    # Plot and analyse the data for enterance and exit events
    charecterization.record_raw(r)
    #print(charecterization.enter)