Exemple #1
0
#!/usr/bin/python3
from ububot.Initializer import UBUBOT
from ububot.Comms.Serial import SerialCommunication, SerialCapture
from ububot.Comms.Socket import SocketCommunication
import argparse
import time

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('N', type=int, default=4)

    forw = True
    with UBUBOT(serial_socket_capture=True) as ububot:
        for i in range(parser.parse_args().N * 2):
            if forw:
                ububot.serial.send("MOVB;B;180;50")
                print('FORWARDS')
            else:
                ububot.serial.send("MOVB;B;-180;50")
                print('BACKWARDS')
            forw = not forw
            time.sleep(1)
Exemple #2
0
#!/usr/bin/python3
from ububot.Initializer import UBUBOT
from ububot.Motor.MotorPair import MotorIdentifier, MotorPairDirection
from time import sleep

if __name__ == '__main__':
    with UBUBOT(motors=True, servos=True) as ububot:
        ububot.servos.get(7).angle(45)
        sleep(1)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_LEFT,
                                 speed=60,
                                 angle=45 * 2.2)
        sleep(2)
        ububot.motors.advance_cm(50, speed=60)
        sleep(2)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_RIGHT,
                                 speed=60,
                                 angle=45 * 2.2)
        sleep(2)
        ububot.motors.advance_cm(70, speed=60)
        sleep(4)
        ububot.motors.advance_cm(70, speed=60)
        sleep(4)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_RIGHT,
                                 speed=60,
                                 angle=45 * 2.2)
        sleep(2)
        ububot.motors.advance_cm(20, speed=60)
        sleep(3)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_LEFT,
                                 speed=60,
Exemple #3
0
#!/usr/bin/python3
from ububot.Motor.Servo import Servo, ChannelOutOfBoundsError
from ububot.Initializer import UBUBOT
from argparse import ArgumentParser
from time import sleep
from sys import stdout

if __name__ == '__main__':

    parser = ArgumentParser(description=__doc__)
    parser.add_argument('-c', '--channel', type=int, default=7)
    parser.add_argument('-a', '--angle', type=float, nargs='+', default=[0, 60, 120])
    parser.add_argument('-sio', '--socket', dest='socket', action='store_const', const=True, default=False)
    parser.add_argument('N', nargs='?', type=int, default=4)
    args = parser.parse_args()

    if not 0 <= args.channel <= 15:
        raise ChannelOutOfBoundsError("Channel = " + str(args.channel) + ". Range = [0, 15]")

    with UBUBOT(servos=True, status_socket=args.socket) as ububot:
        for i in range(args.N):
            for angle in args.angle:
                ububot.servos.get(args.channel).angle(angle)
                print("{}°".format(angle))
                sleep(1)
                stdout.write("\033[F\033[K")
Exemple #4
0
#!/usr/bin/python3
from ububot.Initializer import UBUBOT
from ububot.Motor.MotorPair import MotorIdentifier, MotorPairDirection
from time import sleep


if __name__ == '__main__':
    with UBUBOT(motors=True, relays=True, serial_socket_capture=True, status_socket=True) as ububot:
        ububot.motors.advance_cm(61, speed=100)
        sleep(4)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_LEFT, speed=100, angle=90*2.5)
        sleep(2)
        ububot.motors.advance_cm(40, speed=100)
        sleep(3)
        ububot.relays.get_motor_1().off()
        sleep(1)
        ububot.relays.get_motor_1().on()
Exemple #5
0
        elif key == '3':
            relays[2] = not relays[2]
            ububot.relays.get_light().set_state(relays[2])
            direction = "Relay 3"
        elif key == '4':
            relays[3] = not relays[3]
            ububot.relays.get_buzzer().set_state(relays[3])
            direction = "Relay 4"
        elif key == '5':
            sound = player.play_random()
            direction = "Playing " + sound.name
        elif key == '6':
            player.stop()
            direction = "Stopping sound"
        else:
            ububot.motors.stop()
            direction = "STOP"
        stdout.write("\033[F\033[K")
        print("Direction =", direction)
        key = getChar()
    ububot.motors.stop()

if __name__ == '__main__':
    parser = ArgumentParser(description=__doc__)
    parser.add_argument('-s', '--speed', type=int, default=200)
    parser.add_argument('-sio', '--socket', dest='socket', action='store_const', const=True, default=False)
    args = parser.parse_args()

    with UBUBOT(motors=True, relays=True, serial_socket_capture=args.socket, motors_socket=args.socket, status_socket=args.socket, sensors=args.socket) as ububot, Player() as player:
        main(ububot, args.speed, player)
Exemple #6
0
#!/usr/bin/python3
from ububot.Initializer import UBUBOT
from ububot.Motor.MotorPair import MotorIdentifier, MotorPairDirection
from time import sleep

if __name__ == '__main__':
    with UBUBOT(motors=True) as ububot:
        ububot.motors.advance_cm(30, speed=100)
        sleep(1)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_LEFT,
                                 speed=60,
                                 angle=90 * 2.3)
        sleep(3)
        ububot.motors.advance_cm(200, speed=100)
        sleep(3)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_RIGHT,
                                 speed=60,
                                 angle=90 * 2.3)
        sleep(3)
        ububot.motors.advance_cm(180, speed=100)
        sleep(3)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_RIGHT,
                                 speed=60,
                                 angle=90 * 2.3)
        sleep(3)
        ububot.motors.advance_cm(210, speed=100)
        sleep(3)
        ububot.motors.stop()
Exemple #7
0
#!/usr/bin/python3
from ububot.Initializer import UBUBOT
from ububot.Sensor.IR import SensorEvent
from ububot.Motor.MotorPair import MotorIdentifier, MotorPairDirection
from ububot.Sound.Player import Player, Sounds
from time import sleep
from argparse import ArgumentParser

if __name__ == '__main__':
    parser = ArgumentParser(description=__doc__)
    parser.add_argument('mode', nargs='?', type=int, default=1)
    mode = parser.parse_args().mode
    with UBUBOT(motors=True, sensors=True, motors_socket=True, serial_socket_capture=True, status_socket=True) as ububot, Player() as player:
        if mode == 1:
            ububot.motors.turn_sharp(MotorPairDirection.SHARP_LEFT, 200, 120 * 4)
            sleep(1.2)
            ububot.motors.advance_cm(40, speed=200)
            sleep(1.2)
            ububot.motors.run(MotorIdentifier.LEFT, -200)
            ububot.motors.run(MotorIdentifier.RIGHT, 200)
            input("Press Enter to finish...")
        if mode == 2:
            ububot.motors.run(MotorIdentifier.LEFT, -100)
            ububot.motors.run(MotorIdentifier.RIGHT, -180)
            sleep(1.2)
            ububot.motors.run(MotorIdentifier.LEFT, 180)
            ububot.motors.run(MotorIdentifier.RIGHT, 110)
            sleep(0.8)
            print("Press Ctrl+C to finish...")
            try:
                while True:
Exemple #8
0
        t_speeds = [50, 100, 150, 200]

    if args.advance_speed is not None:
        a_speeds = []
        for speed in args.advance_speed:
            if speed not in a_speeds and speed > 0:
                a_speeds.append(speed)
        if len(a_speeds) == 0:
            raise ValueError('Expected at least one non-zero positive integer')
    else:
        a_speeds = [50, 100, 150, 200]

    print("Starting calibration.")
    print("Press 'c' at any moment to cancel the calibration process.")
    with UBUBOT(motors=True,
                serial_socket_capture=args.socket,
                motors_socket=args.socket) as ububot:
        t_ratios = sharp(ububot, t_speeds, args.angle)
        if t_ratios is None:
            exit(-1)
        a_ratios = advance(ububot, a_speeds, args.distance)
        print()
        print('Turn ratios:')
        for speed, ratio in zip(t_speeds, t_ratios):
            print("SPEED [ {} ] : {:.3f}".format(str(speed).rjust(3), ratio))
        if a_ratios is None:
            exit(-1)
        print('Distance ratios:')
        for speed, ratio in zip(a_speeds, a_ratios):
            print("SPEED [ {} ] : {:.3f}".format(str(speed).rjust(3), ratio))
        print()
Exemple #9
0
#!/usr/bin/python3
from ububot.Sensor.IR import SensorEvent
from ububot.Sensor.SensorGroup import CardinalPosition
from ububot.Initializer import UBUBOT
from time import sleep
from sys import stdout

def callback(pin, state):
    for position in remaining:
        if ububot.sensors.get(position)._pin == pin:
            remaining.remove(position)
            break

if __name__ == '__main__':

    with UBUBOT(sensors=True) as ububot:
        remaining = [position for position in CardinalPosition]

        ububot.sensors.get_east().add_callback(SensorEvent.DETECT_START, callback)
        ububot.sensors.get_north().add_callback(SensorEvent.DETECT_START, callback)
        ububot.sensors.get_south().add_callback(SensorEvent.DETECT_START, callback)
        ububot.sensors.get_west().add_callback(SensorEvent.DETECT_START, callback)
        while len(remaining) > 0:
            print("Remaining:", ", ".join([position.name for position in remaining]))
            sleep(0.1)
            stdout.write("\033[F\033[K")
Exemple #10
0
resolution = (640, 480)
framerate = 12
socket_framerate = 10
claw_channel = 8
plow_channel = 7


def change_light(ububot):
    ububot.relays.get_light().off()
    sleep(0.1)
    ububot.relays.get_light().on()


if __name__ == '__main__':
    with UBUBOT(all=True) as ububot, Player() as player:
        #CameraStream(resolution=resolution, framerate=framerate) as camera, \
        #Streamer(framerate=socket_framerate) as streamer, Player() as player:
        input("Press Enter to continue...")
        ububot.relays.get_buzzer().off()
        sleep(1)
        #camera.add_callback(streamer.set_image)
        player.play(Sounds.WIN_XP_ON)
        ububot.servos.get(plow_channel).angle(50)
        sleep(2)
        ububot.relays.get_buzzer().on()
        ububot.motors.advance_cm(40, speed=100)
        sleep(3)
        ububot.motors.turn_sharp(MotorPairDirection.SHARP_LEFT,
                                 speed=200,
                                 angle=180 * 4)
Exemple #11
0
#!/usr/bin/python3
from ububot.Relay.Relay import Relay
from ububot.Initializer import UBUBOT
from argparse import ArgumentParser
from time import sleep

if __name__ == '__main__':

    parser = ArgumentParser(description=__doc__)
    parser.add_argument('N', nargs='?', type=int, default=4)
    parser.add_argument('-sio',
                        '--socket',
                        dest='socket',
                        action='store_const',
                        const=True,
                        default=False)
    args = parser.parse_args()

    with UBUBOT(relays=True, status_socket=args.socket) as ububot:
        for i in range(args.N):
            print("off")
            ububot.relays.off()
            sleep(1)
            print("on")
            ububot.relays.on()
            sleep(1)