Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from hapi-robo/devel
Browse files Browse the repository at this point in the history
First release
  • Loading branch information
r-oung authored Jul 22, 2020
2 parents 6dd8678 + f995760 commit ea87017
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 52 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 ...
Expand All @@ -24,7 +24,7 @@ cd temipy/
./setup.sh
```

To activate the virtual environment:
Activate the virtual environment:
```
source venv/bin/activate
```
Expand All @@ -33,22 +33,29 @@ 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")
# command the robot to go to a saved location
robot.goto("entrance")
```

See `sample.py` for more details.
65 changes: 47 additions & 18 deletions sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def readme():
author_email="[email protected]",
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",
Expand Down
2 changes: 1 addition & 1 deletion temipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
from .robot import Robot
from .connect import connect
from .connect import connect
65 changes: 43 additions & 22 deletions temipy/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)

0 comments on commit ea87017

Please sign in to comment.