# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI motor tester

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()  # start the robot

    robot.turnMotors(50, 50)  # turn the left and right motors at 50%
    print("Turning both motors")
    robot.wait(5)  # wait for 5 seconds

    robot.turnMotors(50, 0)  # turn the left motor at 50%
    print("Turning left motor")
    robot.wait(5)  # wait for 5 seconds

    robot.turnMotors(0, 50)  # turn the right motor at 50%
    print("Turning right motor")
    robot.wait(seconds=5)  # wait for 5 seconds

    robot.stop()  # stop the robot
#from approxeng.input.wii import WiiRemotePro
#from approxeng.input.wiimote import WiiMote
#from approxeng.input.rockcandy import RockCandy
#
# Then pass in the appropriate class name to the call
# to ControllerResource() as follows:
#       with ControllerResource(controller_class = DualShock3) as joystick:

# ======================================================================================================
# Main program
# ======================================================================================================
try:

    # Variable to indicate if we are still running
    running = True
    robot = RosiRobot()
    robot.start()

    with ControllerResource() as joystick:
        print("Found joystick")
        while running and joystick.connected:

            presses = joystick.check_presses()

            if joystick.presses.start:
                # We want to exit the program
                running = False

            if joystick.presses.cross:
                # We want to stop the robot
                robot.turnMotors(0, 0)
# www.thinkcreatelearn.co.uk
#
# ROSI switch bumper sample solution
#
# Moves forward until the bumper switch is hit, when it turns around

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()

    button = robot.Button(0)  # create a button on input pin 0

    while True:
        if (button.isPressed()):
            robot.stop()  # stop
            robot.turnMotors(-100, -100)  # full speed backward
            robot.backwardDistance(100, centimetres=10)
            robot.spinAngle(180)
        else:
            robot.turnMotors(100, 100)  # full speed forward

        robot.wait(0.1)  # allow some time for Ctrl-C
    # Turn right instead
    spinAngle(180)  # we've already gone 90 left, so need 180 right
    fillSonarDistanceHistory()
    if (min(global_sonarLastDistances) > 20):
        return  # we are free to turn right

    print("We didn't find an exit!")


# ======================================================================================================
# Main program
# ======================================================================================================
try:

    print('Press CTRL+C to quit')
    robot = RosiRobot()
    robot.start()

    global_sonarLastDistances = []

    # Keep running until told to stop
    while True:
        # Get the distance measurement from the sonar sensor
        distance = round(robot.readSonarDistance(), 2)
        print("Distance:", distance, " cm")

        # Save the last few distance measurements so we can avoid spurious readings
        global_sonarLastDistances.append(distance)
        if (len(global_sonarLastDistances) > SONAR_NUM_DISTANCES_TO_KEEP):
            global_sonarLastDistances.pop(0)  # remove the first one
# www.thinkcreatelearn.co.uk
#
# ROSI blob bumper template

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    print('Press CTRL+C to quit')

    robot = RosiRobot()

    robot.start()
    robot.numLightSensors = 1

    while True:
        if robot.lightSensorSeeingBlob():
            robot.stop()  # stop
            break  # exit the program
        else:
            robot.turnMotors(100, 100)  # full speed forward

        robot.wait(0.1)

    robot.finish()
Exemple #6
0
#
# ROSI line following sample solution
# 
# Follows a line on the ground using the light sensors

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException 


# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()
    robot.start()
    robot.numLightSensors = 3

    # These will be set to the desired speed
    leftMotorSpeed = 0
    rightMotorSpeed = 0

    # Keep a count of how many loops since we last saw the line
    cantSeeLineCount = 0

    # Loop until we can't see the line for 50 continous counts
    while cantSeeLineCount<50:
        # Read from the line sensor 
        reading = robot.readLightSensor()
        left = reading[0]
Exemple #7
0
# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI template

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException 


# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()

    # ******** DO SOMETHING HERE ********
    print("1")
    robot.armMoveAngle(0, 0)
    robot.wait(1)
    print("2")
    robot.armMoveAngle(0, 90)
    robot.wait(1)
    print("3")
    robot.armMoveAngle(0, 180)
    robot.wait(1)

    robot.finish()
# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI template

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()

    # ******** DO SOMETHING HERE ********

    robot.finish()

except RosiException as e:
    print(e.value)
except KeyboardInterrupt:
    robot.finish()
# ROSI ultrasonic tester

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException
import math

# ======================================================================================================
# Main program
# ======================================================================================================
try:

    print('Press CTRL+C to quit')

    robot = RosiRobot()

    robot.start()

    global_sonarLastDistances = []

    # Keep running until told to stop
    while True:
        distance = round(robot.readSonarDistance(), 2)
        print(distance)
        robot.wait(seconds=0.5)

    robot.finish()

except RosiException as e:
    print(e.value)
def bd_stop():
    robot.stop()


# ------------------------------------------------------------------------------------------------------
# Function for Blue Dot.  Placeholder for any action we want to take on a double-press on the blue dot.
# ------------------------------------------------------------------------------------------------------
def bd_double_press():
    robot.stop()


# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()
    robot.start()
    robot.printSettings()

    bd = BlueDot()
    bd.when_pressed = bd_move
    bd.when_moved = bd_move
    bd.when_released = bd_stop
    bd.when_double_pressed = bd_double_press

    while running:
        robot.wait(0.1)

except robot.RosiException as e:
    print(e.value)
Exemple #11
0
# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI line following sensor tester

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()
    print("Press Ctrl-C to stop")
    robot.numLightSensors = 1

    while True:
        # Read from the line sensor
        reading = robot.readLightSensor()

        # Print out what we see
        print(reading)

        robot.wait(seconds=0.1)

    robot.finish()
Exemple #12
0
# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException
from approxeng.input.selectbinder import ControllerResource

# ======================================================================================================
# Main program
# ======================================================================================================
try:

    # Variable to indicate if we are still running
    running = True

    robot = RosiRobot()

    robot.start()

    with ControllerResource() as joystick:
        print("Found joystick")
        while running and joystick.connected:

            presses = joystick.check_presses()

            if joystick.presses.start:
                # We want to exit the program
                running = False

            if joystick.presses.cross:
                # ******** DO SOMETHING HERE ********
Exemple #13
0
from threading import Thread


def ledFlash():
    while True:
        led.on()
        robot.wait(1)
        led.off()
        robot.wait(1)


# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()

    led = robot.Led(0)

    # Start thread
    ledThread = Thread(target=ledFlash)
    ledThread.start()

    while True:
        robot.turnMotors(100, 100)
        robot.wait(5)
        robot.turnMotors(-100, -100)
        robot.wait(5)
# ROSI template for line following

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException 


# ======================================================================================================
# Main program
# ======================================================================================================
try:

    print( 'Press CTRL+C to quit')

    robot = RosiRobot()

    robot.start()

    # Set the number of light sensors we have (1, 2 or 3)
    robot.numLightSensors = 3

    # Loop forever (or until Ctrl-C)
    while True:
        # Read from the line sensor 
        reading = robot.readLightSensor()
        left = reading[0]
        centre = reading[1]
        right = reading[2]
        print (left, centre, right)
# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI switch bumper template

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()
    robot.start()
    button = robot.Button(0)  # create a button on input pin 0

    while True:
        if (button.isPressed()):
            robot.stop()  # stop
        else:
            robot.turnMotors(100, 100)  # full speed forward

        robot.wait(0.1)

    robot.finish()

except RosiException as e:
    print(e.value)
except KeyboardInterrupt:
# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI led tester

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()

    robot.start()

    led = robot.Led(channel=0)  # create an led on output channel 0

    led.on()
    robot.wait(seconds=5)
    led.off()

    robot.finish()

except RosiException as e:
    print(e.value)
except KeyboardInterrupt:
    robot.finish()
#
# ROSI blob (light sensor) bumper sample solution
#
# Turns around when it sees a black blob on the ground


# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException 

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    robot = RosiRobot()
    robot.start()
    print("Press Ctrl-C to stop")
    robot.numLightSensors = 1
    robot.tracingOn()

    while True:
        if robot.lightSensorSeeingBlob():
            robot.stop()
            robot.turnMotors(-100,-100)  # full speed backward
            robot.backwardDistance(100,centimetres=15)
            robot.spinAngle(180)            
        else:
            robot.turnMotors(100,100)  # full speed forward
        
        robot.wait(0.1)
Exemple #18
0
# Think Create Learn
# www.thinkcreatelearn.co.uk
#
# ROSI analogue / potentiometer tester

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:

    robot = RosiRobot()

    robot.start()

    analogue = robot.AnalogueIn(3)  # create a button on input pin 3

    while True:
        value = analogue.read()
        print("Value is", value)
        robot.wait(seconds=1)

    robot.finish()

except RosiException as e:
    print(e.value)
except KeyboardInterrupt:
# www.thinkcreatelearn.co.uk
#
# ROSI button tester

# ======================================================================================================
# Imports
# ======================================================================================================
from rosi import RosiRobot, RosiException

# ======================================================================================================
# Main program
# ======================================================================================================
try:
    print('Press CTRL+C to quit')

    robot = RosiRobot()

    robot.start()

    button = robot.Button(0)  # create a button on input pin 0

    while True:
        if (button.isPressed()):
            print("Pressed")
        else:
            print("Not pressed")
        robot.wait(seconds=0.1)  # allow some time for Ctrl-C

    robot.finish()

except RosiException as e: