def __init__(self):
        print('Roomba node!')
        super().__init__('roomba_node')

        PORT = "/dev/ttyUSB0"
        self.adapter = PyRoombaAdapter(PORT)
        self.twist_sub = self.create_subscription(Twist, "/cmd_vel",
                                                  self.twist_callback)
class RoombaNode(Node):
    def __init__(self):
        print('Roomba node!')
        super().__init__('roomba_node')

        PORT = "/dev/ttyUSB0"
        self.adapter = PyRoombaAdapter(PORT)
        self.twist_sub = self.create_subscription(Twist, "/cmd_vel",
                                                  self.twist_callback)

    def twist_callback(self, msg):
        print('callback')
        velocity = msg.linear.x
        yaw_rate = msg.angular.z
        self.adapter.move(velocity, yaw_rate)
예제 #3
0
"""
    Go and  back example with roomba
"""
from time import sleep

import math
from pyroombaadapter import PyRoombaAdapter

PORT = "/dev/ttyUSB0"
adapter = PyRoombaAdapter(PORT)
adapter.move(0.2, math.radians(0.0))  # go straight
sleep(1.0)
adapter.move(0, math.radians(-20))  # turn right
sleep(6.0)
adapter.move(0.2, math.radians(0.0))  # go straight
sleep(1.0)
adapter.move(0, math.radians(20))  # turn left
sleep(6.0)
예제 #4
0
"""
    Play Darth Vader song
"""
from time import sleep

from pyroombaadapter import PyRoombaAdapter

PORT = "/dev/ttyUSB0"
adapter = PyRoombaAdapter(PORT)

adapter.send_song_cmd(0, 9,
                      [69, 69, 69, 65, 72, 69, 65, 72, 69],
                      [40, 40, 40, 30, 10, 40, 30, 10, 80])
adapter.send_play_cmd(0)
sleep(10.0)
예제 #5
0
from time import sleep
import random
from pyroombaadapter import PyRoombaAdapter

if __name__ == '__main__':
    # parse options
    parser = argparse.ArgumentParser(description='keras-pi.')
    parser.add_argument('-m', '--model', default='./model/mnist_deep_model.json')
    parser.add_argument('-w', '--weights', default='./model/weights.20.hdf5')
    parser.add_argument('-l', '--labels', default='./model/labels.txt')

    args = parser.parse_args()

    PORT = '/dev/ttyUSB0'
    roomba = PyRoombaAdapter(PORT)

    camera = PiCamera()
    camera.resolution = (640, 480)

    labels = []
    with open(args.labels,'r') as f:
        for line in f:
            labels.append(line.rstrip())
    print(labels)

    model_pred = model_from_json(open(args.model).read())
    model_pred.load_weights(args.weights)

    # model_pred.summary()
예제 #6
0
args = parser.parse_args()
cmd = args.command.lower()

### Turn on roomba if "on" cmd
if cmd == "on":
    print("Powering on Roomba...")
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(power_on_pin, GPIO.OUT)
    GPIO.output(power_on_pin, GPIO.HIGH)
    time.sleep(power_on_duration_sec)
    GPIO.output(power_on_pin, GPIO.LOW)
    print("Roomba should be powered on")
    exit()

### Establish connection
adapter = PyRoombaAdapter(SERIAL_PORT)

print("Command: %s" % cmd)

if cmd == "clean":
    adapter.start_cleaning()
elif cmd == "off":
    #can't be started again without physical button push
    adapter.turn_off_power()
elif cmd == "stop":
    adapter.change_mode_to_passive()
elif cmd == "bclean":
    #functions same as "clean"
    adapter.send_buttons_cmd(clean=True)
elif cmd == "dock":
    adapter.start_seek_dock()
예제 #7
0
"""
    Go and  back example with roomba
"""
from time import sleep

import numpy as np
from pyroombaadapter import PyRoombaAdapter

PORT = "/dev/ttyUSB0"
adapter = PyRoombaAdapter(PORT)
adapter.move(0.2, np.deg2rad(0.0))  # go straight
sleep(1.0)
adapter.move(0, np.deg2rad(-20))  # turn right
sleep(6.0)
adapter.move(0.2, np.deg2rad(0.0))  # go straight
sleep(1.0)
adapter.move(0, np.deg2rad(20))  # turn left
sleep(6.0)
예제 #8
0
"""
    Go and  back example with roomba
"""
from time import sleep

import numpy as np
from pyroombaadapter import PyRoombaAdapter

PORT = "/dev/ttyUSB0"
adapter = PyRoombaAdapter(PORT)
while (1):
    adapter.move(0.2, np.deg2rad(0.0))  # go straight
예제 #9
0
class RoombaDriverNode(object):
    def __init__(self):
        self.rate = rospy.Rate(66)  # Robot updates data every 15ms

        # Robot customization
        self.port = rospy.get_param("port", "/dev/ttyUSB0")
        self.use_bumpers = rospy.get_param("use_bumpers", False)
        self.use_cliff_sensors = rospy.get_param("use_cliff_sensors", False)
        self.use_ir_receiver = rospy.get_param("use_ir_receiver", False)
        self.use_wheel_drops = rospy.get_param("use_wheel_drops", False)
        self.use_ir_sensors = rospy.get_param("use_ir_sensors", False)
        self.use_brushes = rospy.get_param("use_brushes", False)
        self.use_leds = rospy.get_param("use_leds", False)
        self.use_songs = rospy.get_param("use_songs", False)
        self.use_seven_segment_display = rospy.get_param(
            "use_seven_segment_display", False)

        # Publishers
        self.pub_battery = rospy.Publisher("battery", Battery, queue_size=10)
        self.pub_odom = rospy.Publisher("odom", Odometry, queue_size=10)
        self.pub_bumpers = rospy.Publisher("bumpers",
                                           BumperEvent,
                                           queue_size=10)
        self.pub_buttons = rospy.Publisher("buttons", Battery, queue_size=10)
        if self.use_cliff_sensors:
            self.pub_cliff = rospy.Publisher("cliff",
                                             CliffEvent,
                                             queue_size=10)
        if self.use_ir_receiver:
            self.pub_ir = rospy.Publisher("ir_receivers",
                                          InfraRedEvent,
                                          queue_size=10)
        if self.use_wheel_drops:
            self.pub_wheel_drops = rospy.Publisher("wheel_drops",
                                                   WheelDropEvent,
                                                   queue_size=10)
        if self.use_ir_sensors:
            self.pub_range = rospy.Publisher("range", Range, queue_size=10)
        if self.use_brushes:
            self.pub_brushes = rospy.Publisher("brushes", Brush, queue_size=10)
        if self.use_leds:
            self.pub_leds = rospy.Publisher("leds", SetLeds, queue_size=10)
        if self.use_songs:
            self.pub_song = rospy.Publisher("play_song",
                                            PlaySong,
                                            queue_size=10)
        if self.use_seven_segment_display:
            self.pub_seven_seg_display = rospy.Publisher(
                "seven_segment_display", SevenSegmentDisplay, queue_size=10)

        # Subscribers
        rospy.Subscriber("cmd_vel", Twist, self.cb_cmd_vel)

    def connect(self):
        self.adapter = PyRoombaAdapter(self.port)

    def publish(self):
        sensors = self.adapter.sensors()
        now = rospy.Time.now()

        battery = Battery(stamp=now)
        battery.state = Battery.CORD if sensors[
            "Charging State"] == 1 else Battery.DOCK if sensors[
                "Charging State"] == 2 else Battery.NOT_CHARGING
        battery.level = 100 * sensors["Battery Charge"] / sensors[
            "Battery Capacity"]
        #battery.time_remaining = rospy.Duration(battery.level/(last_charge-))
        self.pub_battery.publish(battery)

        if self.use_cliff_sensors: self.pub_cliff.publish(CliffEvent())
        if self.use_ir_receiver: self.pub_ir.publish()
        if self.use_wheel_drops: self.pub_wheel_drops.publish()
        if self.use_ir_sensors: self.pub_range.publish()
        if self.use_brushes: self.pub_brushes.publish()
        if self.use_leds: self.pub_leds.publish()
        if self.use_songs: self.pub_song.publish()
        if self.use_seven_segment_display: self.pub_seven_seg_display.publish()

    def run(self):
        while not rospy.is_shutdown():
            self.publish()
            self.rate.sleep()
예제 #10
0
 def connect(self):
     self.adapter = PyRoombaAdapter(self.port)