예제 #1
0
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()

romi.square()

romi.circle()

예제 #2
0
#!/usr/bin/python2
#
# Blink the lights connected to the RomiPi
# The neopixel should turn red, yellow, then red
from romipi_astar.romipi_driver import AStar
import time

led_delay_s = 2.0

romi = AStar()

# turn on red LED
romi.leds(True, False, False)
romi.pixels(250, 0, 0)
print("LED RED")
print("PIXEL RED")
time.sleep(led_delay_s)

# turn on yellow LED
romi.leds(False, True, False)
romi.pixels(0, 250, 0)
print("LED YELLOW")
print("PIXEL GREEN")
time.sleep(led_delay_s)

# turn on green LED
romi.leds(False, False, True)
romi.pixels(0, 0, 250)
print("LED GREEN")
print("PIXEL BLUE")
time.sleep(led_delay_s)
예제 #3
0
import threading
import PyLidar3
import math
import time
from romipi_astar.romipi_driver import AStar

romi = AStar()

speed = 0.2  # speed in m/s
direction = 0.0  # direction in radians


def drive():
    while True:
        romi.twist(speed, 0)


x = []
y = []
for _ in range(360):
    x.append(0)
    y.append(0)

port = "/dev/ttyUSB0"  #linux
Obj = PyLidar3.YdLidarX4(
    port)  #PyLidar3.your_version_of_lidar(port,chunk_size)
threading.Thread(target=drive).start()
if (Obj.Connect()):
    print(Obj.GetDeviceInfo())
    gen = Obj.StartScanning()
    t = time.time()  # start time
예제 #4
0
파일: circle.py 프로젝트: limam1/CPE476
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()
linear_ms = 0.0
rotate_rads = 0.0


def update_twist():
    """send twist to driver and change light color if moving"""
    if linear_ms == 0.0 and rotate_rads == 0.0:
        romi.pixels(0, 0, 100)
    else:
        romi.pixels(0, 100, 0)
    romi.twist(linear_ms, rotate_rads)


# all set up, now run the robot
t_end = time.time() + 900
t_end1 = time.time() + 1
while True:
    linear_ms = 0
    rotate_rads = .2
    update_twist()
    if t_end1 < time.time():
        break

# stop motors and shut down light
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('twist_linear',
                    type=float,
                    help='linear component of twist in m/s')
parser.add_argument('twist_angular',
                    type=float,
                    help='angular component of twist in radians/s')
parser.add_argument('time', type=float, help='time in seconds')

args = parser.parse_args()
print(args)

romi = AStar()


def monitor_pose():
    monitor_freq_hz = 2.0
    # move forward for two seconds
    i = 0
    while True:
        print("{:} : poses ->"
              " motor m/s {:}"
              " twist_tuple {:}".format(i / monitor_freq_hz,
                                        romi.read_pose_motors(),
                                        romi.read_pose_twist()))
        # print motor_speeds for two seconds
        i = i + 1
        time.sleep(1.0 / monitor_freq_hz)
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()
linear_ms = 0.0
rotate_rads = 0.0


def getch():
    import sys, tty, termios
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch


def print_instructions():
    print("press w,a,s,d,z to move the robot, q to quit:")


def print_speed():
    print("UPDATED TWIST CMD: linear m/s %0.1f, rotation rad/s %0.1f" %
          (linear_ms, rotate_rads))
예제 #7
0
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()

distance = 10.0
runtime = 15.0

romi.twist(2 * 3.14 * distance / runtime, 2 * 3.14 / runtime)
time.sleep(runtime)

romi.twist(0.0, 0.0)

print("all done.")
#!/usr/bin/python2
#
# Print out the pose estimates
# without setting twist so that the
# user can push the robot around

from romipi_astar.romipi_driver import AStar
import time

romi = AStar()

try:
    romi.reset_encoders()

    while True:
        romi.print_debug_info()
        time.sleep(0.5)
except KeyboardInterrupt:
    pass
except Exception as e:
    print e

romi.close()
예제 #9
0
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

motor_delay_s = 5.0
forward_speed_m_s = 0.25
stop_speed_m_s = 1.25
romi = AStar()

# int main()
# turn off all LEDs
romi.leds(False, False, False)
romi.pixels(0, 0, 0)
print("Displaying Circle Code")
var = input("Press s/S to stop and any key to continue: ")  #input
while var != "s" and var != "S":
    currentTime = time.time()
    nextTime = currentTime + motor_delay_s
    while currentTime < nextTime:  #loops for prev time delay
        romi.twist(forward_speed_m_s, stop_speed_m_s)  # makes a circle
        currentTime = time.time()
    romi.twist(0.0, 0.0)  # stop
    var = input("Press s/S to stop and any key to continue: ")  #input
예제 #10
0
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

motor_delay_s = 2.0
forward_speed_m_s = 0.1
stop_speed_m_s = 0.0
romi = AStar()

def monitor_pose(duration_s):
    monitor_freq_hz = 2.0

    # move forward for two seconds
    for i in range(0, int(duration_s*monitor_freq_hz)):
        print("{:} twist {:}"
              " motor speed m/s {:}"
              " pose_twist {:}".format(
            i / monitor_freq_hz,
            romi.read_twist(),
            romi.read_pose_motors(),
            romi.read_pose_twist()))
        # print motor_speeds for two seconds
        time.sleep(1.0/monitor_freq_hz)

print("initializing...")
romi.pixels(0,0,255)

print("moving forwards...")
# twist format is forward vector, rotation vector
예제 #11
0
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()

distance = 15
sides = 4
for j in range(sides):
    for i in range(distance):
        romi.twist(distance, 0.0)
        time.sleep(1.0)
        romi.twist(0.0, 3.14 / 2)
        time.sleep(1.0)

romi.twist(0.0, 0.0)

print("all done.")
예제 #12
0
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

motor_delay_s = 2.2
forward_speed_m_s = 0.25
stop_speed_m_s = 0.0
romi = AStar()

# int main()
# turn off all LEDs
romi.leds(False, False, False)
romi.pixels(0, 0, 0)

print("Displaying Square Code")
var = input("Press s/S to stop and any key to continue: ")  #input
while var != "s" and var != "S":
    # twist format is forward vector, rotation vector
    # moves in square
    for i in range(4):
        currentTime = time.time()
        nextTime = currentTime + motor_delay_s  # next time
        while currentTime < nextTime:  # loops for prev time
            romi.twist(forward_speed_m_s, stop_speed_m_s)  #go forward
            currentTime = time.time()

        romi.twist(stop_speed_m_s, stop_speed_m_s)  # stop
        currentTime = time.time()
        nextTime = currentTime + (motor_delay_s / 2.0)
        while currentTime < nextTime:  # loops for prev time
            romi.twist(stop_speed_m_s, 3.14159265358979323846 / 2)  #turns
예제 #13
0
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()
linear_ms = 0.1
rotate_rads = 0.5
count = 0
finalCount = 48000


print("initializing...")
#romi.pixels(0,0,255)

print("begin circle...")

while(True):
	romi.twist(linear_ms,rotate_rads)
	count += 1
	if (count == finalCount):
		break


#!/usr/bin/python2
# pixels_utility.py
#
# Manually control the Neopixel colors
# on the Romi
#
# Peter F. Klemperer
# September 26, 2018
from romipi_astar.romipi_driver import AStar
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('red', type=int, help='red (0-255) value of pixel')
parser.add_argument('green', type=int, help='green (0-255) value of pixel')
parser.add_argument('blue', type=int, help='blue (0-255) value of pixel')
args = parser.parse_args()
print(args)

romi = AStar()

# turn on pixel according to arguments
romi.pixels(args.red, args.green, args.blue)
예제 #15
0
#!/usr/bin/python2
#
# Move the robot forwards and backwards
from romipi_astar.romipi_driver import AStar
import time

romi = AStar()
linear_ms = 0.0
rotate_rads = 0.0


def getch():
    import sys, tty, termios
    fd = sys.stdin.fileno()
    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    return ch


def print_instructions():
    print("press a to move in circle, b for square")


# all set up, now run the robot
print_instructions()
while True:
    c = getch()