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)
""" 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)
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() max_count = 0 count = 0 stream = PiRGBArray(camera) try: while True: roomba.move(0.0, np.deg2rad(0.0)) # stop sleep(1.0) camera.capture(stream, 'bgr', use_video_port=True) count += 1 if count > max_count: X = [] img_org = stream.array img = cv2.resize(img_org, (64, 64)) img = img_to_array(img) X.append(img) X = np.asarray(X) X = X/255.0 start = time.time() preds = model_pred.predict(X)
""" 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)
""" 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