Erle Robotics has previously made streamings via YouTube, which allowed viewers to control their Erle-Spider via Twitter with the #ErleSpider hashtag. But this had a problem: it combined two different platforms in a non-intuitive way and that was confusing for the audience. Some people, for example, tried to control the spider via youtube chat.
Trying to solve this problem, I decided to find a solution by fusing both platforms (YouTube and Twitter) into one. Inspired by TwitchPlaysPokemon, I decided to bring the experience to twitch by allowing people to control the spider via twitch chat. Just like TwitchPlaysPokemon made with the Pokemon game.
For this project I used the following hardware:
Step 0 - SetupBefore anything, the first thing you need to do is create two twitch.tv accounts. The first one is for the bot and the other one for the streaming.
Step 1 - Create the botI used aidanrt's Twitch chat/irc bot template available on this github repository.
First, we need to clone the Git repository
git clone https://github.com/aidanrt/twitch-bot
NOTE: for convenience, do this directly in the Erle Brain, not in your PC.
Then, we need to rename config/config_example.py to config/config.py and replace all the placeholders with your bot usename, oauth and channel. 'username' will be your bot username, 'oauth_password' will be authentication token of your bot (you can get it here) and inside 'channels' the streaming channel the bot needs to join (don't forget the # before the username).
Next, we will add the commands needed to make the spider move. These will be 4: !ready, !forward, !backwards, !right and !left. To add these simply add them to src/lib/command_headers.py inside "commands = { }":
# Inside commands = { ... }
'!ready': {
'limit': 30,
'argc': 0,
'return': 'command'
},
'!forward': {
'limit': 30,
'argc': 0,
'return': 'command'
},
'!backwards': {
'limit': 30,
'argc': 0,
'return': 'command'
},
'!right': {
'limit': 30,
'argc': 0,
'return': 'command'
},
'!left': {
'limit': 30,
'argc': 0,
'return': 'command'
}
Now we are going to implement those commands. Inside src/lib/commands create the following files:
- ready.py
# File : ready.py
import time, sys, json
import rospy
from sensor_msgs.msg import Joy
def ready():
rospy.init_node("joy_simulate", anonymous=True)
pub = rospy.Publisher("/joy", Joy, queue_size=10)
msg = Joy()
msg.header.stamp = rospy.Time.now()
valueAxe = 0.0
valueButton = 0
standup_time = 20 #2 seconds
for i in range (0, 20):
msg.axes.append(valueAxe)
for e in range (0, 17):
msg.buttons.append(valueButton)
rate = rospy.Rate(10)
time.sleep(1)
msg.buttons[3] = 1
i=0
bo=True
print "STAND_UP"
while not rospy.is_shutdown() and bo:
i=i+1
if (i>standup_time):
bo=False
msg.buttons[3] = 0
pub.publish(msg)
rate.sleep()
- forward.py
# File : forward.py
import time, sys, json
import rospy
from sensor_msgs.msg import Joy
def forward():
rospy.init_node("joy_simulate", anonymous=True)
pub = rospy.Publisher("/joy", Joy, queue_size=10)
msg = Joy()
msg.header.stamp = rospy.Time.now()
valueAxe = 0.0
valueButton = 0
walking_time = 30 #3 seconds
for i in range (0, 20):
msg.axes.append(valueAxe)
for e in range (0, 17):
msg.buttons.append(valueButton)
rate = rospy.Rate(10)
time.sleep(1)
msg.axes[1] = 1
i=0
bo=True
print "WALKING"
while not rospy.is_shutdown() and bo:
i=i+1
if (i>walking_time):
bo=False
msg.axes[1] = 0
pub.publish(msg)
rate.sleep()
- backwards.py
# File : right.py
import time, sys, json
import rospy
from sensor_msgs.msg import Joy
def backwards():
rospy.init_node("joy_simulate", anonymous=True)
pub = rospy.Publisher("/joy", Joy, queue_size=10)
msg = Joy()
msg.header.stamp = rospy.Time.now()
valueAxe = 0.0
valueButton = 0
walking_time = 30 #3 seconds
for i in range (0, 20):
msg.axes.append(valueAxe)
for e in range (0, 17):
msg.buttons.append(valueButton)
rate = rospy.Rate(10)
time.sleep(1)
msg.axes[1] = -1
i=0
bo=True
print "WALKING"
while not rospy.is_shutdown() and bo:
i=i+1
if (i>walking_time):
bo=False
msg.axes[1] = 0
pub.publish(msg)
rate.sleep()
- right.py
# File : right.py
import time, sys, json
import rospy
from sensor_msgs.msg import Joy
def right():
rospy.init_node("joy_simulate", anonymous=True)
pub = rospy.Publisher("/joy", Joy, queue_size=10)
msg = Joy()
msg.header.stamp = rospy.Time.now()
valueAxe = 0.0
valueButton = 0
turning_time = 30 #3 seconds
for i in range (0, 20):
msg.axes.append(valueAxe)
for e in range (0, 17):
msg.buttons.append(valueButton)
rate = rospy.Rate(10)
time.sleep(1)
msg.axes[2] = -1
i=0
bo=True
print "TURNING RIGHT"
while not rospy.is_shutdown() and bo:
i=i+1
if (i>turning_time):
bo=False
msg.axes[2] = 0
pub.publish(msg)
rate.sleep()
- left.py
import time, sys, json
import rospy
from sensor_msgs.msg import Joy
def left():
rospy.init_node("joy_simulate", anonymous=True)
pub = rospy.Publisher("/joy", Joy, queue_size=10)
msg = Joy()
msg.header.stamp = rospy.Time.now()
valueAxe = 0.0
valueButton = 0
turning_time = 30 #3 seconds
for i in range (0, 20):
msg.axes.append(valueAxe)
for e in range (0, 17):
msg.buttons.append(valueButton)
rate = rospy.Rate(10)
time.sleep(1)
msg.axes[2] = 1
i=0
bo=True
print "TURNING LEFT"
while not rospy.is_shutdown() and bo:
i=i+1
if (i>turning_time):
bo=False
msg.axes[2] = 0
pub.publish(msg)
rate.sleep()
Implemented in ROS, these commands will communicate with the spider to make it actually move. So now, everytime a viewer types !ready in the chat will make the spider stand up. !forward will make it move forward, and so on. But to make that happen, we will need to run the bot.
To run the bot simply add execution permissions by typing
chmod +x serve.py
And then run it
./serve.py
If everything goes fine you will see that the twitch chat bot will join to your chat; and you should be able to make the spider move.
Step 3 : Livestream what is happeningIf you want people to actually see what is happening with the spider, you will need to livestream it. If your ErleBrain has a camera, you can use that for a POV. Since this project was done in a short period of time of a hacking session and for testing purposes, this part was not done but this script might be helpful.
Another option is to livestream from your pc the whole place with a webcam. Here are several tools that will help you.
DemonstrationHere is a short demo.
Comments
Please log in or sign up to comment.