示例#1
0
    def setup(self):
        self.LEFT_TOWER = 85
        self.RIGHT_TOWER = 24
        self.CENTER = 53


        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)
        self.servo = Servo(self.tamp, 23) #pin TBD
        self.red_detected = False
        self.green_detected = False
        self.servo.write(self.CENTER)
        self.counter = 0
        self.servo_bottom = Servo(self.tamp,22)
        self.servo_bottom.write(34)

        self.motor = Motor(self.tamp, 24, 25)
        self.motor.write(True, 250)
        self.jammed = False

        self.conveyor_encoder = Encoder(self.tamp, *self.pins, continuous=True)
        self.prev_encoder_value = 0
        self.conveyor_encoder.update()
        self.timer = Timer()

        self.sorter_delta = 50
示例#2
0
 def __init__(self, tamp):
     self.r2g = 0
     self.g2r = 0
     self.tamp = tamp
     self.color = Color(self.tamp,
                        integrationTime=Color.INTEGRATION_TIME_101MS,
                        gain=Color.GAIN_1X)
示例#3
0
 def setup(self):
     timer = Timer()
     timeoutTimer = Timer()
     leftMotor = Motor(self.tamp, LEFT_DRIVE_CONTROLLER_DIRECTION,
                       LEFT_DRIVE_CONTROLLER_PWM)
     rightMotor = Motor(self.tamp, RIGHT_DRIVE_CONTROLLER_DIRECTION,
                        RIGHT_DRIVE_CONTROLLER_PWM)
     intakeMotor = Motor(self.tamp, HUGS_MOTOR_CONTROLLER_DIRECTION,
                         HUGS_MOTOR_CONTROLLER_PWM)
     color = Color(self.tamp)
     self.check = CheckModule(timer, timeoutTimer, leftMotor, rightMotor,
                              intakeMotor, color)
     self.check.start()
示例#4
0
    def setup(self):
        self.LEFT_TOWER = 83.4
        self.RIGHT_TOWER = 27
        self.CENTER = 54


        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)
        self.servo = Servo(self.tamp, 23) #pin TBD
        self.red_detected = False
        self.green_detected = False
        self.servo.write(self.CENTER)
        self.counter = 0
        self.timer = Timer()
示例#5
0
    def setup(self):

        self.screen = pygame.display.set_mode((300, 300))

        print 'Made it'
        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)
        self.timer = Timer()

        self.max_r = 1
        self.max_g = 1
        self.max_b = 1
        self.max_temp = 1
        self.max_lux = 1
        self.max_opacity = 1
        self.max_dif = 1
        self.max_rb_dif = 1
        self.max_gb_dif = 1
        self.rb = 1
        self.gb = 1
        self.r_values = []
        self.g_values = []
示例#6
0
    def setup(self):
        ####################
        ####  EE SETUP  ####
        ####################

        # Motor object representing the left motor.
        self.leftMotor = Motor(self.tamp, LEFT_DRIVE_CONTROLLER_DIRECTION,
                               LEFT_DRIVE_CONTROLLER_PWM)
        # Encoder object for the left motor.
        self.leftEncoder = Encoder(self.tamp, LEFT_DRIVE_ENCODER_YELLOW,
                                   LEFT_DRIVE_ENCODER_WHITE)
        # Motor object representing the right motor.
        self.rightMotor = Motor(self.tamp, RIGHT_DRIVE_CONTROLLER_DIRECTION,
                                RIGHT_DRIVE_CONTROLLER_PWM)
        # Encoder object for the right motor.
        self.rightEncoder = Encoder(self.tamp, RIGHT_DRIVE_ENCODER_YELLOW,
                                    RIGHT_DRIVE_ENCODER_WHITE)

        # Motor object representing the intake mechanism motors.
        self.intakeMotor = Motor(self.tamp, HUGS_MOTOR_CONTROLLER_DIRECTION,
                                 HUGS_MOTOR_CONTROLLER_PWM)
        # Encoder object for the intake motor.
        self.intakeEncoder = Encoder(self.tamp, HUGS_MOTOR_ENCODER_YELLOW,
                                     HUGS_MOTOR_ENCODER_WHITE)

        # Motor object representing the conveyor belt motor.
        self.conveyorMotor = Motor(self.tamp, BELT_MOTOR_CONTROLLER_DIRECTION,
                                   BELT_MOTOR_CONTROLLER_PWM)
        # Encoder object for the conveyor belt motor.
        self.conveyorEncoder = Encoder(self.tamp, BELT_MOTOR_ENCODER_YELLOW,
                                       BELT_MOTOR_ENCODER_WHITE)

        # Long range IR sensors
        self.irBL = LRIR(self.tamp, LONG_DISTANCE_IR_BL)
        self.irBR = LRIR(self.tamp, LONG_DISTANCE_IR_BR)
        self.irFL = LRIR(self.tamp, LONG_DISTANCE_IR_FL)
        self.irFR = LRIR(self.tamp, LONG_DISTANCE_IR_FR)

        # Color sensor
        self.color = Color(self.tamp)

        # Limit switches
        self.conveyorLimSwitch = DigitalInput(self.tamp, CONVEYOR_LIMIT_SWITCH)
        self.blockLimSwitch = DigitalInput(self.tamp, BLOCK_LIMIT_SWITCH)

        # Servo controlling the door of the collection chamber.
        self.backDoorServo = Servo(self.tamp, SERVO_PIN)
        # Make sure the door is closed
        self.backDoorServo.write(SERVO_CLOSE)

        # The switch that tells the program that the competition has started
        self.competitionModeSwitch = DigitalInput(self.tamp, COMPETITION_MODE)

        #################################
        ####  INTERNAL MODULE SETUP  ####
        #################################

        # Timer object to moderate checking for intake errors.
        self.intakeTimer = Timer()
        # Are the intake motors reversing? True if so, False if going forwards.
        self.intakeDirection = False
        # Start the intake motor.
        self.intakeMotor.write(self.intakeDirection, INTAKE_POWER)

        # Wall Follow object
        self.wallFollow = WallFollow(self.leftMotor, self.rightMotor, Timer(),
                                     self.irFL, self.irFR, self.irBL,
                                     self.irBR)

        # A timer to make sure timesteps are only 10 times/second
        self.timestepTimer = Timer()
        # Timer object describing how long the current module has been running.
        self.moduleTimer = Timer()
        # Timer for the whole game
        self.gameTimer = Timer()

        # Runs the PICKUP process
        self.pickup = PickupModule(self.moduleTimer, self.conveyorLimSwitch,
                                   self.conveyorMotor, self.conveyorEncoder)
        # Runs the DROPOFF process
        self.dropoff = DropoffModule(self.moduleTimer, self.backDoorServo,
                                     self.rightMotor, self.leftMotor,
                                     self.rightEncoder)
        # Runs the FOLLOW process TODO: Fix forward to actually mean forward.
        self.follow = FollowModule(self.moduleTimer, self.leftMotor,
                                   self.rightMotor, self.intakeMotor,
                                   self.wallFollow, FORWARD_SPEED,
                                   self.blockLimSwitch)
        # Runs the CHECK process. TODO: pass in proper timers.
        self.check = CheckModule(self.moduleTimer, self.leftMotor,
                                 self.rightMotor, self.intakeMotor, self.color)
        # Waits for the game to start
        self.off = OffModule(self.gameTimer, self.competitionModeSwitch)

        # Describes which stage of the program is running.
        self.module = MODULE_OFF
示例#7
0
 def setup(self):
     self.color = Color(self.tamp,
                        integrationTime=Color.INTEGRATION_TIME_101MS,
                        gain=Color.GAIN_1X)
     self.timer = Timer()
示例#8
0
    def setup(self):
        #Pygame stuff
        pygame.init()
        self.screen = pygame.display.set_mode((300, 300))

        self.TicpIn = 4480 / 2.875

        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)

        self.uIR = DigitalInput(self.tamp, 17)
        self.uIR.val = 1

        self.servo = Servo(self.tamp, 9)
        self.servo.bottom = 0
        self.servo.top = 200
        self.servo.speed = 30
        self.servo.write(self.servo.bottom)
        self.servoval = self.servo.bottom
        self.delta = 0

        self.sorter = Servo(self.tamp, 5)
        self.sorter.center = 90
        self.sorter.right = 25
        self.sorter.left = 165
        self.sorter.speed = 15

        self.sorter.write(self.sorter.center)
        self.sorterval = self.sorter.center
        self.dsorter = 0

        self.encoderL = Encoder(self.tamp, 22, 23)
        self.encoderR = Encoder(self.tamp, 21, 20)

        self.init_time = time.time()
        # self.encoderL = Encoder(self.tamp, 23, 22)
        # self.encoderR = Encoder(self.tamp, 21, 20)

        #motor left
        self.motorL = Motor(self.tamp, 2, 4)
        self.motorLdrive = 0
        self.motorL.write(1, 0)
        #self.deltaL = 1
        #self.motorvalL = 0

        #motor right
        self.motorR = Motor(self.tamp, 1, 3)
        self.motorRdrive = 0
        self.motorR.write(1, 0)
        #self.deltaR = 1
        #self.motorvalR = 0

        #gyro

        self.gyro = Gyro(self.tamp, self.ss_pin, integrate=True)
        self.initAngle = self.gyro.val
        self.newAngle = 0
        self.blockAngle = 0
        self.blockDistance = 0
        print "initial angle:" + str(self.initAngle)

        self.prevGyro = 0
        self.drift = -.02875
        self.totalDrift = 0

        self.drifts = []

        self.PID = PID(.5, 1, 0.15)

        self.fwdVel = 0
        self.turnVel = 0
        self.turn = 0
        self.MoveArm, self.Top, self.Bottom = False, 0, 0

        self.Sort = 0
        self.SortPause = 0

        self.State = 1

        self.timer = Timer()
示例#9
0
    def setup(self):



        self.TicpIn = 4480/2.875

        self.ir_array = Ir_array(self.tamp, 16, 15, 14, 40, 11, 10)

        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)

        self.uIR = DigitalInput(self.tamp, 17)
        self.uIR.val = 1

        self.servo = Servo(self.tamp, 9)
        self.servo.bottom = 0
        self.servo.top = 200
        self.servo.speed = 30
        self.servo.write(self.servo.bottom)
        self.servoval = self.servo.bottom
        self.delta = 0


        self.sorter = Servo(self.tamp, 5)
        self.sorter.center = 90
        self.sorter.right = 25
        self.sorter.left = 165
        self.sorter.speed = 15

        self.sorter.write(self.sorter.center)
        self.sorterval = self.sorter.center
        self.dsorter = 0

        self.encoderL = Encoder(self.tamp, 22, 23)
        self.encoderR = Encoder(self.tamp, 21, 20)

        self.init_time = time.time()
        # self.encoderL = Encoder(self.tamp, 23, 22)
        # self.encoderR = Encoder(self.tamp, 21, 20)

        #motor left
        self.motorL = Motor(self.tamp, 2, 4)
        self.motorLdrive = 0
        self.motorL.write(1,0)
        #self.deltaL = 1
        #self.motorvalL = 0
        
        #motor right
        self.motorR = Motor(self.tamp,1, 3)
        self.motorRdrive = 0
        self.motorR.write(1,0)
        #self.deltaR = 1
        #self.motorvalR = 0

        #gyro
        
        self.gyro = Gyro(self.tamp, self.ss_pin, integrate=True)
        self.initAngle = self.gyro.val
        self.newAngle = 0
        self.blockAngle = 0
        self.blockDistance = 0
        # print "initial angle:"+str(self.initAngle)
        
        self.Follow = 'Right'
        self.IRs = {'Left': [0, 1, 2], 'Right': [5, 4, 3]}

        self.prevGyro = 0
        self.drift = -.02875
        self.totalDrift = 0

        self.drifts = []
        
        
        self.PID=PID(.5, 1, 0.15)
        self.IRPID = PID(10, 5, .15)

        self.fwdVel = 30
        self.turnVel = 0
        self.MoveArm, self.Top, self.Bottom = False, 0, 0

        self.Sort = 0
        self.SortPause = 0

        self.State = 1
        
        self.timer = Timer()
示例#10
0
from tamproxy.devices import Color
import tamproxy
import pygame
import sys
import numpy as np
import time
import itertools
import os

if __name__ == '__main__':
    with tamproxy.TAMProxy() as tamp:
        color = Color(tamp, integrationTime=Color.INTEGRATION_TIME_2_4MS, gain=Color.GAIN_60X)
        screen = pygame.display.set_mode([500,500])
        max_c = np.float32([0,0,0,0])

        saves = []

        colors = dict(
            red=[],
            green=[],
            none=[]
        )

        ideal_colors = dict(
            red=[255, 0, 0],
            green=[0,255,0],
            none=[0, 0, 0]
        )

        names = colors.keys()
        i = 0
    def setup(self):
        # initialize sensors, settings, start timers, etc.
        self.gameTimer = Timer()

        self.motorGripper = Motor(self.tamp, 23, 3)
        self.motorLeft = Motor(self.tamp, 7, 22)
        self.motorRight = Motor(self.tamp, 0, 21)
        self.motorval = 0
        self.motorLeft.write(1, 0)
        self.motorRight.write(1, 0)
        self.motorGripper.write(1, 0)
        self.currentGripperLevel = 2
        print "Motors connected."

        self.servoDoor = Servo(self.tamp, 20)
        self.servovalDoor = self.DOOR_CLOSE_POS
        self.servoDoor.write(self.DOOR_CLOSE_POS)
        self.timerDoor = Timer()
        self.servoGripper = Servo(self.tamp, 10)
        self.servovalGripper = self.GRIPPER_CLOSE_POS
        self.servoGripper.write(self.servovalGripper)
        self.timerGripper = Timer()
        print "Servos connected."

        self.timer = Timer()
        self.gyro = Gyro(self.tamp, 9)
        print "Gyro connected."
        self.theta = self.gyro.val
        self.dT = .01

        self.cam = cv2.VideoCapture(0)

        print "Camera connected."

        self.color = Color(self.tamp,
                           integrationTime=Color.INTEGRATION_TIME_101MS,
                           gain=Color.GAIN_1X)

        frontLeftIR_pin = 14
        self.frontLeftIR = AnalogInput(self.tamp, frontLeftIR_pin)
        frontRightIR_pin = 15
        self.frontRightIR = AnalogInput(self.tamp, frontRightIR_pin)
        leftIR_pin = 16
        self.leftIR = AnalogInput(self.tamp, leftIR_pin)
        rightIR_pin = 17
        self.rightIR = AnalogInput(self.tamp, rightIR_pin)

        # Initialize PID Values
        self.P = 10
        self.I = 0  #5
        self.D = 0
        self.last_diff = 0
        self.integral = 0
        self.desiredAngle = self.theta
        self.finishedCollectingBlock = False
        self.finishedDiscardingBlock = False

        self.timer = Timer()
        self.state = ExploreState()
        # self.state = CollectBlockState()

        self.blocksCollected = 0
        self.leftIRVals = deque([])
        self.rightIRVals = deque([])
        self.frontRightIRVals = deque([])
        self.frontLeftIRVals = deque([])

        # Starts the robot
        print "Robot setup complete."
示例#12
0
 def __init__(self, tamp):
     self._dev = Color(tamp, integrationTime=Color.INTEGRATION_TIME_2_4MS, gain=Color.GAIN_60X)