diff --git a/README.md b/README.md index 92a3044..b995b71 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ # temi Connect Python Package -Classes and functions to control temi using Python scripts. +Control temi using Python scripts over MQTT. ## Prerequisites * [Python 3](https://www.python.org/downloads/) * Python [virtualenv](https://virtualenv.pypa.io/en/stable/installation.html) -* Connect APK installed on temi, see [here](https://github.com/hapi-robo/connect) +* Connect APK installed on temi, see [here](https://github.com/hapi-robo/connect/tree/devel/android) * MQTT broker. Free brokers for testing: * [Eclipse](http://test.mosquitto.org/) * [Mosquitto](http://mqtt.eclipse.org) * [HiveMQ](http://broker.hivemq.com) -## Ubuntu/MacOS Setup +## Ubuntu / MacOS Setup Clone this repository: ``` git clone ... @@ -24,7 +24,7 @@ cd temipy/ ./setup.sh ``` -To activate the virtual environment: +Activate the virtual environment: ``` source venv/bin/activate ``` @@ -33,18 +33,23 @@ source venv/bin/activate ## Usage Make sure temi is connected to an MQTT broker via the Connect app. -Sample Python script: +Edit the `sample.py` script and adjust the `parameters` appropriately, then run: ``` -import temipy as temi +python sample.py +``` + +## Sample Script +``` +import temipy as temi -temi_serial = "01234567890" +TEMI_SERIAL = "01234567890" # connect to the MQTT server mqtt_client = temi.connect("test.mosquitto.org", 1883) # create robot object -robot = temi.Robot(mqtt_client, "temi_serial") +robot = temi.Robot(mqtt_client, TEMI_SERIAL) # command the robot to speak robot.tts("Going to the Entrance") @@ -52,3 +57,5 @@ robot.tts("Going to the Entrance") # command the robot to go to a saved location robot.goto("entrance") ``` + +See `sample.py` for more details. diff --git a/sample.py b/sample.py index 7b8d567..97673b5 100644 --- a/sample.py +++ b/sample.py @@ -4,51 +4,80 @@ """ import temipy as temi +import time -temi_serial = "01234567890" +# parameters +MQTT_HOST = "test.mosquitto.org" +MQTT_PORT = 1883 +TEMI_SERIAL = "01234567890" # connect to the MQTT server -mqtt_client = temi.connect("test.mosquitto.org", 1883) +mqtt_client = temi.connect(MQTT_HOST, MQTT_PORT) # create robot object -robot = temi.Robot(mqtt_client, "temi_serial") +robot = temi.Robot(mqtt_client, TEMI_SERIAL) - -command the robot to speak +# -------------------------------------------------------------- +# TEXT-TO-SPEECH COMMANDS +# -------------------------------------------------------------- +# command the robot to speak robot.tts("Going to the Entrance") -command the robot to go to a saved location -robot.goto("entrance") - -# play YouTube video by passing in a video ID -robot.youtube("ZsEano0qwcg") -time.sleep(10) # wait 10 seconds before performing next action +# -------------------------------------------------------------- +# WAYPOINT COMMANDS +# -------------------------------------------------------------- +# command the robot to go to a saved location +robot.goto("entrance") +# -------------------------------------------------------------- +# MOVE COMMANDS +# -------------------------------------------------------------- # tilt the robot's head to +55 degrees (absolute angle) robot.tilt(+45) -time.sleep(3) # wait 3 seconds for action to complete +time.sleep(3) # wait 3 seconds for action to complete # tilt the robot's head to -15 degrees (absolute angle) robot.tilt(-15) -time.sleep(3) # wait 3 seconds for action to complete +time.sleep(3) # wait 3 seconds for action to complete # tilt the robot's head to +30 degrees (relative angle) robot.tilt_by(+30) -time.sleep(3) # wait 3 seconds for action to complete +time.sleep(3) # wait 3 seconds for action to complete # tilt the robot's head to -10 degrees (relative angle) robot.tilt_by(-10) -time.sleep(3) # wait 3 seconds for action to complete - +time.sleep(3) # wait 3 seconds for action to complete # rotate the robot by 90 degrees (relative angle) robot.rotate(90) -time.sleep(5) # wait 5 seconds for action to complete +time.sleep(5) # wait 5 seconds for action to complete # rotate the robot by -30 degrees (relative angle) robot.rotate(-30) -time.sleep(5) # wait 5 seconds for action to complete +time.sleep(5) # wait 5 seconds for action to complete + + +# -------------------------------------------------------------- +# MEDIA COMMANDS +# -------------------------------------------------------------- +# play YouTube video by passing in a video ID +robot.youtube("ZsEano0qwcg") +time.sleep(30) # wait 30 seconds before performing next action + +# play online video by passing a URL +robot.video( + "https://roboteam-assets.s3.eu-central-1.amazonaws.com/ui/skills/tutorials/videos/intorducing+temi.mp4" +) +time.sleep(30) # wait 30 seconds before performing next action + +# show webview by passing a URL +robot.webview("https://www.robotemi.com/") +time.sleep(5) # wait 5 seconds before performing next action +robot.webview("https://www.his.co.jp/en/") +time.sleep(5) # wait 5 seconds before performing next action +robot.webview("https://hapi-robo.com/") +time.sleep(5) # wait 5 seconds before performing next action diff --git a/setup.py b/setup.py index 3b5ea92..d148389 100644 --- a/setup.py +++ b/setup.py @@ -16,9 +16,7 @@ def readme(): author_email="r.oung@hapi-robo.com", url="https://github.com/", packages=setuptools.find_packages(), - install_requires=[ - "paho-mqtt", - ], + install_requires=["paho-mqtt",], classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", diff --git a/temipy/__init__.py b/temipy/__init__.py index ff21bec..37d99f1 100644 --- a/temipy/__init__.py +++ b/temipy/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- from .robot import Robot -from .connect import connect \ No newline at end of file +from .connect import connect diff --git a/temipy/robot.py b/temipy/robot.py index 1bdd00f..8b66c66 100644 --- a/temipy/robot.py +++ b/temipy/robot.py @@ -25,10 +25,10 @@ def rotate(self, angle): """ print("[CMD] Rotate: {} [deg]".format(angle)) - + topic = "temi/" + self.serial + "/command/move/turn_by" payload = json.dumps({"angle": angle}) - + self.client.publish(topic, payload, qos=0) def translate(self, value): @@ -42,8 +42,8 @@ def translate(self, value): elif math.copysign(1, value): topic = "temi/" + self.serial + "/command/move/backward" else: - pass # do nothing - + pass # do nothing + self.client.publish(topic, "{}", qos=0) def tilt(self, angle): @@ -100,27 +100,16 @@ def tts(self, text): self.client.publish(topic, payload, qos=1) - def audio(self, url): - """Play audio - - """ - print("[CMD] Play Audio: {}".format(url)) - - topic = "temi/" + self.serial + "/command/media/audio" - payload = json.dumps({"url": url}) - - self.client.publish(topic, payload, qos=1) - - def image(self, url): - """Display image + # def audio(self, url): + # """Play audio - """ - print("[CMD] Show Image: {}".format(url)) + # """ + # print("[CMD] Play Audio: {}".format(url)) - topic = "temi/" + self.serial + "/command/media/image" - payload = json.dumps({"url": url}) + # topic = "temi/" + self.serial + "/command/media/audio" + # payload = json.dumps({"url": url}) - self.client.publish(topic, payload, qos=1) + # self.client.publish(topic, payload, qos=1) def video(self, url): """Play video @@ -143,3 +132,35 @@ def youtube(self, video_id): payload = json.dumps({"video_id": video_id}) self.client.publish(topic, payload, qos=1) + + def webview(self, url): + """Show webview + + """ + print("[CMD] Show Webview: {}".format(url)) + + topic = "temi/" + self.serial + "/command/media/webview" + payload = json.dumps({"url": url}) + + self.client.publish(topic, payload, qos=1) + + def call(self, room_name): + """Start a call + + """ + print("[CMD] Call: {}".format(room_name)) + + topic = "temi/" + self.serial + "/command/call/start" + payload = json.dumps({"room_name": room_name}) + + self.client.publish(topic, payload, qos=1) + + def hangup(self): + """End a call + + """ + print("[CMD] Hangup") + + topic = "temi/" + self.serial + "/command/call/end" + + self.client.publish(topic, "{}", qos=1)