示例#1
0
def run(bot_address):
    print("Connecting to {0}.".format(bot_address))
    bot = MorseRobot(bot_address)
    bot.reset()
    bot.connect()
    print("Connected")
    # bot.sense.unsubscribe()
    while True:
        draw_now(bot)
示例#2
0
def run(bot_address):
    with MorseRobot(bot_address) as robot:
        robot.connect()
        robot.reset()
        # robot.debug()
        # It would be nice to get bump sensing to work for additional obsticle avoidance.
        robot.whenever("prox_left", above=OBSTACLE_DISTANCE,
                       max_firing_freq=5).do(avoid_left)
        robot.whenever("prox_right",
                       above=OBSTACLE_DISTANCE,
                       max_firing_freq=5).do(avoid_right)
        robot.whenever("picked_up", value=True, max_firing_freq=1).do(stop)
        robot.whenever("nominal", value=True, max_firing_freq=1).do(start)
        robot.whenever("dot_left_of_dash", value=True,
                       max_firing_freq=.5).do(left_indicator_on)
        robot.whenever("dot_left_of_dash", value=False,
                       max_firing_freq=.5).do(left_indicator_off)
        robot.whenever("dot_right_of_dash", value=True,
                       max_firing_freq=.5).do(right_indicator_on)
        robot.whenever("dot_right_of_dash", value=False,
                       max_firing_freq=.5).do(right_indicator_off)
        try:
            robot.drive(NOMINAL_SPEED)
            while True:
                robot.sleep(0.5)
        except KeyboardInterrupt:
            robot.stop()
            pass
示例#3
0
 def json2Packets1(self, json_str):
     print(json_str)
     commands = json.loads(json_str)
     converse = {
         WWMedia.WWSound.WWSoundDot.HOWDY: "hi",
         WWMedia.WWSound.WWSoundDot.HOLD_ME: "ayayay",
         WWMedia.WWSound.WWSoundDot.READYSET: "brrp",
         WWMedia.WWSound.WWSoundDash.HOWSGOING: "elephant",
         WWMedia.WWSound.WWSoundDash.LETS_GO: "confused2"
     }
     packets = two_packet_wrappers()
     print("two")
     if '300' in commands:
         robot = MorseRobot()
         packets.packet2_bytes_num = 0
         packets.packet1_bytes_num = 20
         myfile = converse[commands['300']['file']]
         byte_array = robot.say(myfile)
         packets.packet1_bytes = byte_array
         print("say", myfile, byte_array)
     if '205' in commands:
         robot = MorseRobot()
         packets.packet2_bytes_num = 0
         packets.packet1_bytes_num = 20
         degree = commands['205']['degree']
         byte_array = robot.turn(degree)
         packets.packet1_bytes = byte_array
         print("turn", degree, byte_array)
     return packets
示例#4
0
def run(bot_address):
    print("Connecting to {0}.".format(bot_address))
    bot = MorseRobot(bot_address)
    bot.reset()
    bot.connect()
    print("Connected")
    # bot.sense.unsubscribe()
    while True:
        draw_now(bot)
示例#5
0
def run(bot_address):
    with MorseRobot(bot_address) as robot:
        robot.connect()
        robot.reset()
        try:
            while True:
                robot.sleep(.5)
                os.system('clear')
                os.system('setterm -cursor off')
                for key, value in robot.sensor_state.iteritems():
                    print("{:<20}:{:6}".format(key, value))
                os.system('setterm -cursor on')
        except KeyboardInterrupt:
            robot.stop()
            pass
 def setUp(self):
     self.bot = MorseRobot(None)
     self.bot.command = MagicMock()
class MorseRobotCommandsTest(unittest.TestCase):
    def setUp(self):
        self.bot = MorseRobot(None)
        self.bot.command = MagicMock()

    def _assert_command_called(self, command_name, command_value):
        self.bot.command.assert_called_once_with(
            command_name,
            bytearray(command_value.decode("hex"))
        )
        self.bot.command.reset_mock()

    def _move_tester(self, distance, speed, command):
        self.bot.move(distance, speed)
        self._assert_command_called("move", command)

    def test_move_1000_forward_fast(self):
        self._move_tester(1000, 600, "e800000682030080")

    def test_move_1000_backward_fast(self):
        self._move_tester(-1000, 600.0, "18000006823c0081")

    def test_move_500_backward_slow(self):
        self._move_tester(-500, 80, "0c0000186a3e0081")

    def test_turn_360_right(self):
        self.bot.turn(-360)
        self._assert_command_called("move", "00008c082e40c080")

    def test_turn_360_left(self):
        self.bot.turn(360)
        self._assert_command_called("move", "000074082e800080")

    def test_stop(self):
        self.bot.stop()
        self._assert_command_called("drive", "000000")

    def test_forward_fast(self):
        self.bot.drive(300)
        self._assert_command_called("drive", "2c0001")

    def test_backward_normal(self):
        self.bot.drive(-200)
        self._assert_command_called("drive", "380007")

    def test_spin_right(self):
        self.bot.spin(-200)
        self._assert_command_called("drive", "003838")

    def test_spin_left(self):
        self.bot.spin(200)
        self._assert_command_called("drive", "00c800")

    def test_red_neck(self):
        self.bot.neck_color("red")
        self._assert_command_called("neck_color", "ff0000")

    def test_lime_left_ear(self):
        self.bot.left_ear_color("lime")
        self._assert_command_called("left_ear_color", "00ff00")

    def test_blue_right_ear(self):
        self.bot.right_ear_color("blue")
        self._assert_command_called("right_ear_color", "0000ff")

    def test_fuchsia_head(self):
        self.bot.head_color("Fuchsia")
        self._assert_command_called("head_color", "ff00ff")

    def test_rest(self):
        self.bot.reset()
        self._assert_command_called("reset", "04")

    def test_min_yaw(self):
        self.bot.head_yaw(-53)
        self._assert_command_called("head_yaw", "cb")

    def test_max_yaw(self):
        self.bot.head_yaw(53)
        self._assert_command_called("head_yaw", "35")

    def test_min_pitch(self):
        self.bot.head_pitch(-5)
        self._assert_command_called("head_pitch", "fb")

    def test_max_pitch(self):
        self.bot.head_pitch(10)
        self._assert_command_called("head_pitch", "0a")

    def say(self):
        self.bot.say("hi")
        self._assert_command_called("say", bytearray(NOISES["hi"]))
示例#8
0
 def setUp(self):
     self.bot = MorseRobot()
     self.bot.command = MagicMock()
示例#9
0
class MorseRobotCommandsTest(unittest.TestCase):
    def setUp(self):
        self.bot = MorseRobot()
        self.bot.command = MagicMock()

    def _assert_command_called(self, command_name, command_value):
        self.bot.command.assert_called_once_with(
            command_name, bytearray(command_value.decode("hex")))
        self.bot.command.reset_mock()

    def _move_tester(self, distance, speed, command):
        self.bot.move(distance, speed)
        self._assert_command_called("move", command)

    def test_move_1000_forward_fast(self):
        self._move_tester(1000, 600, "e800000682030080")

    def test_move_1000_backward_fast(self):
        self._move_tester(-1000, 600.0, "18000006823c0081")

    def test_move_500_backward_slow(self):
        self._move_tester(-500, 80, "0c0000186a3e0081")

    def test_turn_360_right(self):
        self.bot.turn(-360)
        self._assert_command_called("move", "00008c082e40c080")

    def test_turn_360_left(self):
        self.bot.turn(360)
        self._assert_command_called("move", "000074082e800080")

    def test_stop(self):
        self.bot.stop()
        self._assert_command_called("drive", "000000")

    def test_forward_fast(self):
        self.bot.drive(300)
        self._assert_command_called("drive", "2c0001")

    def test_backward_normal(self):
        self.bot.drive(-200)
        self._assert_command_called("drive", "380007")

    def test_spin_right(self):
        self.bot.spin(-200)
        self._assert_command_called("drive", "003838")

    def test_spin_left(self):
        self.bot.spin(200)
        self._assert_command_called("drive", "00c800")

    def test_red_neck(self):
        self.bot.neck_color("red")
        self._assert_command_called("neck_color", "ff0000")

    def test_lime_left_ear(self):
        self.bot.left_ear_color("lime")
        self._assert_command_called("left_ear_color", "00ff00")

    def test_blue_right_ear(self):
        self.bot.right_ear_color("blue")
        self._assert_command_called("right_ear_color", "0000ff")

    def test_fuchsia_head(self):
        self.bot.head_color("Fuchsia")
        self._assert_command_called("head_color", "ff00ff")

    def test_rest(self):
        self.bot.reset()
        self._assert_command_called("reset", "04")

    def test_min_yaw(self):
        self.bot.head_yaw(-53)
        self._assert_command_called("head_yaw", "cb")

    def test_max_yaw(self):
        self.bot.head_yaw(53)
        self._assert_command_called("head_yaw", "35")

    def test_min_pitch(self):
        self.bot.head_pitch(-5)
        self._assert_command_called("head_pitch", "fb")

    def test_max_pitch(self):
        self.bot.head_pitch(10)
        self._assert_command_called("head_pitch", "0a")

    def say(self):
        self.bot.say("hi")
        self._assert_command_called("say", bytearray(NOISES["hi"]))