def __init__(self, shared_stuff, cmd_queue, sensor_thread): self.shared = shared_stuff self.cmd_queue = cmd_queue self.arm = arm.robotArm(self.shared) self.drive = driveUnit.driveUnit() self.current_speed = [None, None] self.linedet = se.LineDetector() self.state = None self.stored_state = None self.has_package = self.shared["hasPackage"] = False self.station_queue = [] self.flush_timer = time.time() self.arm_return_pos = None self.carry_pos = (0, 100, 130, 0, 150, 140)
import time from sensorThread import sensorThread from driveUnit import driveUnit from regulator import Regulator shared_stuff = {"lineSensor" : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "distance" : [0, 0], "armPosition" : [0, 0, 255, 4, 5, 5], "errorCodes" : ["YngveProgrammedMeWrong"], "motorSpeed" : [50, 50], "latestCalibration" : "0000-00-00-15:00", "autoMotor" : True, "autoArm" : False, "regulator" : [0, 0]} drive_unit = driveUnit() sensor_thread = sensorThread(shared_stuff) sensor_thread.daemon=True sensor_thread.start() regulator = Regulator(shared_stuff) regulator.daemon = True regulator.start() l, r = 0, 0 while True: time.sleep(0.01) l, r = shared_stuff["regulator"]
"""a simple testprogram for the pcThread class that is used to connects to a user and receives commands and sends data back""" from pcThread import pcThread import Queue import time import copy import driveUnit import arm robot_arm=arm.robotArm() driver=driveUnit.driveUnit() commandQueue=Queue.Queue() sensorList= {"lineSensor" : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], "distance" : [0, 0], "armPosition" : [0, 0, 255, 4, 5, 5], "errorCodes" : ["YngveProgrammedMeWrong"], "motorSpeed" : [70, 70], "latestCalibration" : "0000-00-00-15:00", "autoMotor" : True, "autoArm" : False, "regulator" : [0, 0], "error" : 0} pcThreadObject=pcThread(commandQueue,sensorList) pcThreadObject.daemon=True pcThreadObject.start() while True: if not commandQueue.empty(): command=(commandQueue.get()) if command[0]=="motorSpeed": left=int(command[1][0]) right=int(command[1][1]) driver.setMotorLeft(left)
from driveUnit import driveUnit from joystick import Joystick import time drive=driveUnit() joy=Joystick() while True: driveUnit.setMotorLeft((-joy.y_axis()-joy.x_axis())*512) driveunit.setMotorRight((-joy.y_axis()+joy.x_axis())*512) time.sleep(0.1)