def kick(self):
        robot = robot_com.robot()
        robot.dribbler_on()
        robot.charge()
        print "charge"
        time.sleep(2)
        print "kick"
        robot.kick()

        robot.all_off()
    def test_drive(self):
        self.running = True
        robot = robot_com.robot()

        robot.battery = True

        robot.dribbler_on()
        time.sleep(1)

        robot.go_forward(20)
        time.sleep(0.5)

        robot.all_off()
    def __init__(self,debug,camera,gate):
        """
        Initialisation of robot devices and videoprocessing module
        """
        self.debug = debug
        self.camera = camera
        self.gate = gate
        
        self.robot=robot_com.robot()
        self.CV=videoprocessing.VideoProcessingOmni(self.camera,self.debug)

        #Main variables
        self.running = True
        self.ball_at_dribbler = False

        #Searching
        self.no_balls_frame_counter = 0
        self.no_gates_frame_counter = 0
        self.last_turn_right = True#ball
        self.gate_right = random.randint(0,1)#gate

        #Drive between gates
        self.gate_state = gate
        
        #Turn to gate
        self.around_the_ball = True
        self.gate_found = 0
        self.start_avoiding_obstacles = 0
        self.driving_between_gates = 0
        self.dribbler_ball_lost = 0

        self.find_ball_after_kick = 0 #Frames more

        #Drive to ball
        self.going_very_fast = 0
        self.ball_found = 0

        #Coilgun
        self.kick_time = 0
        self.coilgun_charging = False
        
        #Screen resolution
        self.screen_x = 320.0
        self.screen_y = 240.0

        #Timeout for going ahead
        self.obstacle_ahead = 0
    def robot_values(self):
        self.running = True
        robot = robot_com.robot()

        robot.dribbler_on()
        time.sleep(1)
        robot.dribbler_off()

        while self.running:
            time.sleep(0.5)
            
            robot.check_battery()
            print "Battery: ",robot.battery

            
            gate = robot.which_gate()
            print "Gate: ",gate

            ball_at_dribbler = robot.ball_at_dribbler()
            print "Ball at dribbler: ",ball_at_dribbler

        robot.all_off()
    def manual_control(self,cam_n):
        self.running = True
        """
        Turn on robot and camera
        """
        cv2.namedWindow( "Camera", cv.CV_WINDOW_AUTOSIZE )
        cam = cv2.VideoCapture(cam_n)
        cam.set(cv.CV_CAP_PROP_FRAME_WIDTH, 320)
        cam.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 240)
        robot = robot_com.robot()

        #coilgun
        robot.charge()
        kick_time = time.time()

        #variables

        while self.running:
            """Show camera image"""
            retval,  frame = cam.read()
            if retval:
                cv2.imshow( "Camera", frame )
            """Charge coilgun"""
            if time.time() - kick_time > 1:
                robot.charge()
            """Read keyboard interrupts"""
            key = cv2.waitKey(50)
            if key == 107:
                print "kick"
                robot.kick()
                kick_time = time.time()
            elif key == 32:
                print "stop"
                robot.stop()
            elif key == 2490368:
                print "forward"
                robot.go_forward(30)
            elif key == 2621440:
                print "backward"
                robot.go_backward(20)
            elif key == 2424832:
                print "turn left"
                robot.turn_left(15)
            elif key == 2555904:
                print "turn right"
                robot.turn_right(15)
            elif key == 97:
                print "go left"
                robot.go_left(20)
            elif key == 100:
                print "go right"
                robot.go_right(20)
            elif key == 27:
                self.running = False
                break

            
            if key!=-1:
                print key

        robot.all_off()
        cv2.destroyAllWindows()
        cam.release()
Example #6
0
import robot_com
import time

robot = robot_com.robot()

action = 6
robot.pid_control(1, 1)
robot.pid_control(2, 1)
robot.pid_control(3, 1)

if action == 1:  # Go forward
    print "\nGoing forward"
    robot.go_pid(1, -80)
    robot.go_pid(2, 80)
    time.sleep(1)
    robot.go_pid(1, -170)
    robot.go_pid(2, 170)
    time.sleep(1)
elif action == 2:  # Go backward
    print "\nGoing backward"
    robot.go_pid(1, 70)
    robot.go_pid(2, -70)
elif action == 3:  # Go turn left
    print "\nTurning LEFT"
    robot.go_pid(1, 10)
    robot.go_pid(2, 10)
    robot.go_pid(3, 10)
elif action == 4:  # Go turn right
    print "\nTurning RIGHT"
    robot.go_pid(1, -4)
    robot.go_pid(2, -4)