Exemple #1
0
def fast_conf():
    #config vitesse rotation
    robot.com("-X -x5 -y12 -m1")

    #config acceleration lineaire
    robot.com("-X -x500 -y500 -m0")

    #config pid
    robot.com("-D -x0.0001 -y0.0004 -t-0.000 -m0")
    robot.com("-D -x0.5 -y-0.2 -t-0.000 -m1")
Exemple #2
0
def init_robot():
    global black_button_pressed
    try:
        GPIO.setup(robot.trig_button, GPIO.IN)
        GPIO.setup(robot.col_button, GPIO.IN)
        GPIO.setup(robot.but1_button, GPIO.IN)
        GPIO.setup(robot.but2_button, GPIO.IN)
        GPIO.add_event_detect(robot.but2_button,
                              GPIO.FALLING,
                              callback=black_button_callback,
                              bouncetime=300)
    except:
        pass
    boot_ok = False
    while (boot_ok == False):
        black_button_pressed = False
        print("BOOT ok.")
        if exists(robot.asserv_out_file) == False:
            print("start first robot deamon")
            robot.my_lcd.write("no deamon...")
            quit()
        if exists(robot.asserv_in_file) == False:
            print("start first robot deamon")
            robot.my_lcd.write("no deamon...")
            quit()

        print("ca va passer?")
        #config angulaire
        #        fast_conf()

        print("stop asserv")
        robot.com("-B -m0")
        print("motor 1 back")
        robot.com("-B -x-0 -m1")
        print("motor 2 back")
        robot.com("-B -x-0 -m2")

        print("les choses serieuses")
        robot.my_lcd.write("deamon connected...")
        # reponse=robot.com("-E")
        # print(reponse)

        print("changer 3 fois la couleur pour selectionner la couleur")
        robot.my_lcd.write("chg 3 times col")
        GPIO.wait_for_edge(robot.col_button, GPIO.RISING)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
            continue
        print("changer 2 fois la couleur pour selectionner la couleur")
        robot.my_lcd.write("chg 2 times col")
        GPIO.wait_for_edge(robot.col_button, GPIO.RISING)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
            continue
        print("changer 1 fois la couleur pour selectionner la couleur")
        robot.my_lcd.write("chg 1 times col")
        GPIO.wait_for_edge(robot.col_button, GPIO.RISING)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
            continue

        robot.my_lcd.write("color : ")
        robot.my_lcd.write("press blue then")
        while GPIO.input(robot.but1_button) == 1:
            if GPIO.input(robot.col_button) == 1:
                robot.color = "jaune"
                robot.my_lcd.lcd_display_string("jaune ", 1, 8)
            else:
                robot.color = "violet"
                robot.my_lcd.lcd_display_string("violet", 1, 8)
            if (black_button_pressed == True):
                print("black button pressed, it should continue")
                continue
            time.sleep(0.1)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
        if GPIO.input(robot.trig_button) == 0:
            robot.my_lcd.write("remove trigger")
        GPIO.wait_for_edge(robot.trig_button, GPIO.RISING)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
            continue
        robot.my_lcd.write("insert trigger")
        GPIO.wait_for_edge(robot.trig_button, GPIO.FALLING)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
            continue
        robot.my_lcd.write("press blue again")
        GPIO.wait_for_edge(robot.but1_button, GPIO.FALLING)
        if (black_button_pressed):
            continue
        robot.my_lcd.write("red button and blue again")
        GPIO.wait_for_edge(robot.but1_button, GPIO.FALLING)
        if (black_button_pressed):
            continue

        print("couleur robot", robot.color)
        if (robot.color == "jaune"):
            reponse = robot.com("-Y -x500 -y 500 -t1.57079632679")

            robot.my_lcd.write("righ !")
            fthewall("derriere")
            robot.turn(-1.57079632679, 0)
            while (robot.com("-E") != "yes"):
                time.sleep(0.1)
        else:
            reponse = robot.com("-Y -x500 -y 2500 -t4.71238898038")
            robot.my_lcd.write("left !")
            fthewall("devant")
            robot.turn(1.57079632679, 0)
            while (robot.com("-E") != "yes"):
                time.sleep(0.1)

        print("F*** The Wall!")
        robot.my_lcd.write("f the wall : ")
        time.sleep(1)
        robot.my_lcd.write("go! ")
        fthewall("gauche")

        print("placement en position initiale")
        if (robot.color == "jaune"):
            print("pour les JAUNE")
            #            reponse=robot.com("-G -x470 -y250 -t3.14159265359 -m0")
            robot.go_direct(470, 250, 3.14159265359, -1, False)
        else:
            print("pour le VIOLET")
            #            reponse=robot.com("-G -x470 -y2750 -t3.14159265359 -m0")
            robot.go_direct(470, 2750, 3.14159265359, -1, False)
        print(reponse)

        truc = ""
        while (robot.com("-E") != "yes"):
            time.sleep(0.1)

        print("wait for trigger")
        GPIO.wait_for_edge(robot.trig_button, GPIO.RISING)
        if (black_button_pressed == True):
            print("black button pressed, it should continue")
            continue
            time.sleep(0.1)
        boot_ok = True
Exemple #3
0
def fthewall(cote):
    print("stop asserv")
    robot.com("-B -m0")
    time.sleep(0.1)
    print("motor 1 back")
    robot.com("-B -x0.75 -m1")
    time.sleep(0.1)
    print("motor 2 back")
    robot.com("-B -x0.75 -m2")
    time.sleep(0.1)
    time.sleep(2)
    reponse = ""
    reponse = robot.com("-V")
    print("speed response:", reponse)
    speed = shlex.split(reponse)

    while (abs(float(speed[0])) > 0.01 or abs(float(speed[1])) > 0.01):
        time.sleep(0.1)
        reponse = robot.com("-V")
        speed = shlex.split(reponse)
        print("speed response:", reponse)
        print(speed[0])
        print(speed[1])

    if cote == "gauche":
        print("bump cote gauche....")
        print("-Y -x-" + str(-1500 + robot.robot_base) + " -t" +
              str(3.14159265359 + robot.angle_base))
        reponse = robot.com("-Y -x" + str(0 + robot.robot_base) + " -t" +
                            str(3.14159265359 + robot.angle_base))
    elif cote == "droite":
        reponse = robot.com("-Y -x" + str(2000 - robot.robot_base) + " -t" +
                            str(0 + robot.angle_base))
    elif cote == "devant":
        reponse = robot.com("-Y -y" + str(3000 - robot.robot_base) + " -t" +
                            str(1.57079632679 + robot.angle_base))
    elif cote == "derriere":
        reponse = robot.com("-Y -y" + str(0 + robot.robot_base) + " -t" +
                            str(4.71238898038 + robot.angle_base))
    else:
        print("bump rien....")

    robot.com("-B -m-1")
    #on avance a nouveau
    if cote == "gauche":
        reponse = robot.com("-G -r -x0 -y-220 -t0 -m0")
    else:
        reponse = robot.com("-G -r -x0 -y-150 -t0 -m0")
    print("on attent l'arrivee du robot...")
    while (robot.com("-E") != "yes"):
        time.sleep(0.1)
Exemple #4
0
if os.getuid() != 0:
    print("il faut etre admin (sudo)")
    robot.my_lcd.write("not root")
    quit()

#timer.start_robot_daemon()
robot.my_lcd.write("go 2019!")

timer.start_robot_daemon()
robot.my_lcd.write("daemon start")
servo.open_servo()
time.sleep(0.5)
servo.close_servo()
servo.servo(0, 0)

robot.com("-X -x500 -y500 -m0")

robot.com("-D -x0.0001 -y0.0004 -t-0.000 -m0")
robot.com("-D -x0.5 -y-0.2 -t-0.000 -m1")

boot.init_robot()
thread_1 = timer.timer()
thread_1.start()
#thread_2 = timer.unbreak()
#thread_2.start()
#depart:450;250;pi
robot.set_lidar()
score = 0
if (robot.color == "jaune"):
    #sortie
    robot.go_arc(270, 450, 1.50, 1, False)
Exemple #5
0
def servo(id, pos):
    robot.com("-S -t" + str(pos) + " -m" + str(id))
    print("il faut etre admin (sudo)")
    robot.my_lcd.write("not root")
    quit()

#timer.start_robot_daemon()
robot.my_lcd.write("go 2019!")

timer.start_robot_daemon()
robot.my_lcd.write("daemon start")
open_servo()
time.sleep(0.5)
close_servo()
servo(0,0)
GPIO.setup(robot.trig_button,GPIO.IN)

robot.com("-X -x500 -y500 -m0")

robot.com("-D -x0.0001 -y0.0004 -t-0.000 -m0")
robot.com("-D -x0.5 -y-0.2 -t-0.000 -m1")
GPIO.wait_for_edge(robot.trig_button, GPIO.RISING)

thread_1 = timer.timer()
thread_1.start()
robot.set_lidar()
robot.com("-Y -x1000 -y250 -t1.57")
robot.go_direct(1000,1250,1.57,1,False)
open_servo()
robot.go_direct(1000,350,1.57,-1,False)
#    time.sleep(0.5)
#    robot.go_direct(250,2200,1.50,1,False)
#    servo(0,1.5)
Exemple #7
0
#            0x090 0x27    /*P8.7, button 6*/
#            0x094 0x27    /*P8.8, button 7 /
#            0x044 0x27    /*P8.32 button 5*/
#            0x0dc 0x27    /*P9.23 button 3*/

import time
import boot
import robot
import opponent

boot.fast_conf()

robot.com("-S -m0 -t0")
robot.com("-S -m1 -t1.5")
robot.com("-S -m3 -t0")
while (True):
    i = 0
    while (opponent.check_danger() == False):
        if (i == 2):
            robot.my_lcd.write("  .")
            i = 0
        if (i == 1):
            robot.my_lcd.write(" . ")
            i = 2
        if (i == 0):
            robot.my_lcd.write(".  ")
            i = 1

    robot.my_lcd.write("detection!")
    robot.com("-S -m0 -t0.5")
    time.sleep(0.3)
Exemple #8
0
import time
import boot
import robot
import opponent




robot.unset_lidar()
#config vitesse rotation
robot.com("-X -x5 -y12 -m1")
time.sleep(0.1)

#config acceleration lineaire
robot.com("-X -x700 -y800 -m0")
time.sleep(0.1)

#config pid
robot.com("-D -x0.002 -y0.0001 -t-0.000 -m0")
#boot.fast_conf()

robot.com("-X -x5 -y12 -m1")
time.sleep(0.1)

#config acceleration lineaire, vitesse puis acceleration
robot.com("-X -x500 -y00 -m0")
time.sleep(0.1)

#config pid

robot.com("-X -x300 -y100 -m0")