Exemple #1
0
def main():
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('serial_port', type=str)
    parser.add_argument('--port', type=int, default=9342)
    parser.add_argument('--hostname', type=str, default='localhost')
    parser.add_argument('--verbose', action='store_true', default=False)
    args = parser.parse_args()

    robot = Robot(args.serial_port, IO=UsbHandler)

    loop = IOLoop()
    app = Application([
        (r'/', WsHandler),
        (r'/scratch-extension', HttpScratchHandler),
    ])

    WsHandler.robot = robot
    WsHandler.ioloop = loop
    WsHandler.verbose = args.verbose

    ext = scratch.generate_extension('luos', robot, args.hostname, args.port)
    HttpScratchHandler.extension = ext

    print('Scratch extension url: "http://{}:{}/scratch-extension"'.format(args.hostname, args.port))

    app.listen(args.port)
    loop.start()
Exemple #2
0
    def test_loooooong_name(self):
        with closing(Robot(fakerobot.host)) as robot:
            mod = random.choice(robot.modules)

            length = random.randint(robot._max_alias_length + 1,
                                    robot._max_alias_length + 100)
            long_name = self.random_name(length)

            with self.assertRaises(ValueError):
                robot.rename_module(mod.alias, long_name)
Exemple #3
0
    def test_add_evt_cb(self):
        with closing(Robot(fakerobot.host)) as robot:
            robot.cb_trigger = Event()

            def dummy_cb(evt):
                robot.cb_trigger.set()

            evt = choice(list(robot.my_button.possible_events))
            robot.my_button.add_callback(evt, dummy_cb)
            robot.cb_trigger.wait()
            robot.my_button.remove_callback(evt, dummy_cb)
Exemple #4
0
    def test_first_command(self):
        with closing(Robot(fakerobot.host)) as robot:
            sent = Event()

            def my_send(msg):
                sent.set()

            robot._send = my_send

            robot.my_servo.target_position = 0
            sent.wait()
Exemple #5
0
    def test_unexisting_module(self):
        with closing(Robot(fakerobot.host)) as robot:
            while True:
                length = random.randint(1, robot._max_alias_length)
                name = self.random_name(length)

                if not hasattr(robot, name):
                    break

            with self.assertRaises(ValueError):
                robot.rename_module(name, 'oups')
Exemple #6
0
    def test_unknwon_evt(self):
        def dummy_cb(evt):
            pass

        with closing(Robot(fakerobot.host)) as robot:
            mod = robot.my_potentiometer
            while True:
                evt = ''.join(choice(ascii_lowercase) for i in range(8))
                if evt not in mod.possible_events:
                    break

            with self.assertRaises(ValueError):
                mod.add_callback(evt, dummy_cb)
Exemple #7
0
    def test_rename(self):
        with closing(Robot(fakerobot.host)) as robot:
            for _ in range(5):
                length = random.randint(1, robot._max_alias_length)
                mod = random.choice(robot.modules)

                old = mod.alias
                new = self.random_name(length)

                robot.rename_module(old, new)

                self.assertTrue(hasattr(robot, new))
                self.assertFalse(hasattr(robot, old))
Exemple #8
0
    def test_servoing_evt(self):
        with closing(Robot(fakerobot.host)) as robot:
            robot._synced = Event()

            def on_move(evt):
                robot.my_servo.position = evt.new_value
                robot._synced.set()

            robot.my_potentiometer.add_callback('moved', on_move)

            robot._synced.wait()
            self.assertEqual(robot.my_potentiometer.position,
                             robot.my_servo.position)
Exemple #9
0
    def test_speed_control(self):
        with closing(Robot(fakerobot.host)) as robot:
            # Stop sync to make sure the fake robot
            # does not change the position anymore.
            robot.close()

            servo = robot.my_servo

            servo.target_speed = 0
            self.assertEqual(servo.target_position, 90)

            servo.target_position = 180
            self.assertEqual(servo.target_speed, 100)
Exemple #10
0
    def test_spamming(self):
        with closing(Robot(fakerobot.host)) as robot:
            robot.i = 0

            def my_send(msg):
                robot._io.send(msg)
                robot.i += 1

            robot._send = my_send

            for p in range(180):
                robot.my_servo.position = p

            sleep(robot._heartbeat_timeout + random())
            self.assertTrue(robot.i < 10)
            self.assertTrue(robot.alive)
Exemple #11
0
    def test_possible_events(self):
        with closing(Robot(fakerobot.host)) as robot:
            for mod in robot.modules:
                self.assertTrue(isinstance(mod.possible_events, set))

            self.assertTrue('pressed' in robot.my_button.possible_events)
Exemple #12
0
 def test_cmd(self):
     with closing(Robot(fakerobot.host)) as robot:
         pos = randint(0, 180)
         robot.my_servo.position = pos
         self.assertEqual(robot.my_servo.position, pos)
Exemple #13
0
 def test_modules(self):
     with closing(Robot(fakerobot.host)) as robot:
         for mod in robot.modules:
             self.assertTrue(hasattr(robot, mod.alias))
Exemple #14
0
def main():
    pygame.mixer.pre_init(44100, -16, 2, 2048)
    pygame.mixer.init()
    pygame.init()
    print("pygame started")

    # configuration spectacle
    FLASHDURATION = 1.0  #durée du temps de flash en secondes
    TEMPSPECTACLE = 3600  # en Secondes
    TEMPSFIN = 25.0  # en seconde avant la fin

    FIRSTALERT = 300  # en seconde avant la fin
    FIRSTALERTDURATION = 5  # en seconde

    SECONDALERT = 120  # en seconde avant la fin
    SECONDALERTDURATION = 5  # en seconde

    # sons
    gong_sound = '/home/pi/Desktop/gong.wav'
    stress_sound = '/home/pi/Desktop/stress.wav'
    stop_sound = '/home/pi/Desktop/stop.wav'
    start_sound = '/home/pi/Desktop/start.wav'
    bip_sound = '/home/pi/Desktop/bip.wav'

    # Luos system connection
    print("robot connection")
    robot = Robot('/dev/ttyAMA0')

    # env variable
    pressed = False
    light = False
    instant = 0.0
    start = False
    first_buzz = -1.0
    end = False
    first_alert = False
    first_alert_stop = False
    second_alert = False
    second_alert_stop = False

    robot.switch_mod.state = True
    time.sleep(2)
    robot.switch_mod.state = False

    while True:
        time.sleep(0.01)
        # ******************* buzzer management ***************************
        if ((pressed == False) and robot.button_mod.pressed):
            light = not light
            if (first_buzz < 0.0):
                first_buzz = time.time()
            instant = time.time()
            robot.switch_mod.state = light
            if (start):
                pygame.mixer.Channel(1).play(pygame.mixer.Sound(stop_sound))
                start = False
            else:
                pygame.mixer.Channel(1).play(pygame.mixer.Sound(start_sound))
                start = True

        pressed = robot.button_mod.pressed

        if (light and ((time.time() - instant) >= FLASHDURATION)):
            light = False
            robot.switch_mod.state = light

        # ******************** time management *************************
        # temps fin
        if (((time.time() - first_buzz) >= (TEMPSPECTACLE - TEMPSFIN))
                and (first_buzz > 0.0)):
            ratio = ((time.time() - first_buzz - TEMPSPECTACLE + TEMPSFIN) /
                     TEMPSFIN) * 100
            robot.switch_mod.state = True
            if (end == False):
                pygame.mixer.Channel(0).play(pygame.mixer.Sound(stress_sound))
                pygame.mixer.Channel(2).play(pygame.mixer.Sound(bip_sound),
                                             loops=-1)
            end = True
            if (ratio > 100.0):
                pygame.mixer.Channel(0).play(pygame.mixer.Sound(gong_sound))
                pygame.mixer.Channel(2).stop()
                robot.switch_mod.state = False
                time.sleep(5)
                break

        # first alert
        if (((time.time() - first_buzz) >= (TEMPSPECTACLE - FIRSTALERT))
                and (first_buzz > 0.0)):
            if (first_alert == False):
                print("first alert")
                robot.switch_mod.state = True
                pygame.mixer.Channel(2).play(pygame.mixer.Sound(bip_sound),
                                             loops=-1)
                first_alert = True
            if (((time.time() - first_buzz) >=
                 (TEMPSPECTACLE - FIRSTALERT + FIRSTALERTDURATION))
                    and (first_alert_stop == False)):
                pygame.mixer.Channel(2).stop()
                robot.switch_mod.state = False
                first_alert_stop = True
                print("first alert stop")

        # second alert
        if (((time.time() - first_buzz) >= (TEMPSPECTACLE - SECONDALERT))
                and (first_buzz > 0.0)):
            if (second_alert == False):
                print("second alert")
                robot.switch_mod.state = True
                pygame.mixer.Channel(2).play(pygame.mixer.Sound(bip_sound),
                                             loops=-1)
                second_alert = True
            if (((time.time() - first_buzz) >=
                 (TEMPSPECTACLE - SECONDALERT + SECONDALERTDURATION))
                    and (second_alert_stop == False)):
                pygame.mixer.Channel(2).stop()
                robot.switch_mod.state = False
                second_alert_stop = True
                print("second alert stop")
Exemple #15
0
 def test_ws_reception(self):
     with closing(Robot(fakerobot.host)) as robot:
         self.assertTrue(robot.modules)
         self.assertTrue(robot.name)
Exemple #16
0
 def test_ws_connection(self):
     with closing(Robot(fakerobot.host)):
         pass
Exemple #17
0
    def __init__(self, host):
        self.robot = Robot(host)
        self.io = self.robot._io

        self.ws = None
Exemple #18
0
 def test_life_cycle(self):
     robot = Robot(fakerobot.host)
     self.assertTrue(robot.alive)
     robot.close()
     self.assertFalse(robot.alive)
Exemple #19
0
from pyluos import Robot
from orbita import Actuator
import time

a = Actuator()

r = Robot('/dev/cu.usbserial-DN05NM0L')
r.gate.delay = 10
r.disk_bottom.rot_position = False
r.disk_middle.rot_position = False
r.disk_top.rot_position = False

# ##########Luos Parameters############

r.disk_bottom.encoder_res = 5
r.disk_middle.encoder_res = 5
r.disk_top.encoder_res = 5

r.disk_bottom.setToZero()
r.disk_middle.setToZero()
r.disk_top.setToZero()

r.disk_bottom.reduction = 232
r.disk_middle.reduction = 232
r.disk_top.reduction = 232

r.disk_bottom.wheel_size = 60.0
r.disk_middle.wheel_size = 60.0
r.disk_top.wheel_size = 60

r.disk_bottom.positionPid = [9, 0.02, 100]
    #stop motors
    def stop_motor(self, motor):
        if motor == 0 or motor == 2:
            motor_right.compliant = True  # disable the motor
            time.sleep(0.5)
        if motor == 1 or motor == 2:
            motor_left.compliant = True  # disable the motor
            time.sleep(0.5)


#test   area ::
if __name__ == "__main__":
    print("deep in the main function")
    # Set the Object by connecting Rpy by IP
    r = Robot("raspberrypi.local")
    if Robot is None:
        print("Cannot connect to Pi")

    print("loading modules :\n")
    print(r.modules)

    print("setting motor controls :\n")
    # get the motor alias (anyway to have it dynamically ?)
    motor_right = r.controlled_mot0
    motor_left = r.controlled_moto

    print("setting class :\n")
    zer = motor_control()
    print("running set_trans_speed :\n")
    zer.set_trans_speed(1000, 2)  # 1000mm/second = 1m/s