Author: Fasermaler
ROS Teleop package that works with the twitch chat API to receive commands from Twitch chat.
teleop-twist-twitch
uses normal ROS geometry twist messages and is compatible with other robots. A simulation demo is included within this repository.
Warning: The author is not responsible for any damage caused by rogue and unchecked robot tele-operation. Please take necessary precautions before deploying this to a physical robot.
Chat Test and functionality is based off the Chat Samples from the twitchdev GitHub repo.
Teleop component is based off the teleop twist keyboard package from the ros-teleop GitHub repo.
Rover demonstration is modified from ThiruVenthan's article on medium.
- Ubuntu 16.04 computer
- ROS Kinetic
- ROS Gazebo
- Twitch Account
If you require assistance with installing ROS Kinetic and ROS Gazebo, the instructions are provided in the last section.
Take note of the the keywords
as there are multiple types of keys being used in the setup.
-
Login to Twitch.
-
Go to the developer console to manage apps and create a new app
How to fill in:
- Name: twitch-plays-teleop
- OAuth URL: http://localhost
- Category: Chat bot
-
Return to the apps console and select the newly created app to view the client ID (copy it somewhere safe). This is called the
client ID
. -
Go to the Twitch Chat Auth Generator while logged into your Twitch account.
-
Generate a key and copy it somewhere safe as well. This is called the
token
. -
Go to the Twitch stream settings and copy the private stream key. This is the
stream key
.
-
Install the python IRC library:
$ pip install irc
-
Clone the repo!
$ git clone https://github.com/Fasermaler/Teleop_twist_twitch
-
Navigate to the
teleop_twist_twitch.py
file$ cd Teleop_twist_twitch/tp-teleop_ws/src/teleop-twist-twitch/
-
Open the file using
nano
/vim
/gedit
:$ nano teleop_twist_twitch.py # nano $ vim teleop_twist_twitch.py # vim $ gedit teleop_twist_twitch.py # gedit
-
On lines
17
to20
there should be the following:username = client_id = token = channel =
Fill in the details accordingly:
username
: teleop-twitch-botclient_id
: client ID obtained from the developer consoletoken
: OAuth token obtained from the chat Auth generatorchannel
: Your Twitch username
-
Return to the main ROS workspace:
$ cd ~/Teleop_twist_twitch/tp-teleop_ws/
-
Run a
catkin_make
on the ROS workspace:$ catkin_make
-
Source the workspace using the
setup.bash
file:$ source devel/setup.bash
-
That's it for now, the workspace is good to go!
Open Broadcaster Software is used to stream the gazebo workspace on your twitch stream.
-
Install FFMPEG:
$ sudo apt-get install ffmpeg
-
Add the ppa for OBS:
$ sudo add-apt-repository ppa:obsproject/obs-studio $ sudo apt-get update
-
Install OBS:
$ sudo apt-get install obs-studio
-
Start OBS from the Ubuntu Search
-
Navigate to the bottom right menu:
-
Select
settings
-
Go to
stream
under the settings window:- Service: Twitch
- Server: Auto
- Stream Key: Enter your
stream key
-
Click
ok
-
Start Gazebo via terminal:
$ gazebo
-
Under the
Source
window in OBS, click the+
button.. The source window is at the bottom, second from the left. -
Leave
Create new
selected and clickok
-
Under the window dropdown menu, select "Gazebo":
-
Click
ok
and close Gazebo. OBS will remember that Gazebo will be the source of the stream in the future.
-
Start up the rover demo:
$ roslaunch rover_gazebo rover_world.launch
This will also start the
roscore
, so starting it separately is not necessary. -
Start up the
teleop_twist_twitch
node:$ rosrun teleop_twist_twitch teleop_twist_twitch.py
-
Before streaming, start typing commands into your twitch chat to test if the robot responds. Here are the default commands:
help - Displays the help and commands up - bot moves forward down - bot moves down left - bot moves left right - bot moves right stop - bot stops
-
Once you are satisfied, open OBS and click on "start streaming". OBS should have saved the Gazebo window settings or streaming.
-
That's it! Enjoy Twitch plays Teleop!
teleop-twist-twitch
uses normal ROS geometry twist messages which means it is compatible with other ROS robots!
To run with an actual robot, simply copy the teleop-twist-twitch
within the tp-teleop-ws
workspace folder into whichever ROS workspace you are using.
- Start the
roscore
and the robot - Continue from step 2-5 of the demo instructions in the previous section
However, once again to re-iterate:
Warning: The author is not responsible for any damage caused by rogue and unchecked robot tele-operation. Please take necessary precautions before deploying this to a physical robot.
The following instructions were taken from the ROS wiki kinetic install guide.
-
Set up the sources list:
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
-
Set up the keys:
$ sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
-
Update the OS packages:
$ sudo apt-get update
Note: Remember to get into the habit of doing a TimeShift image before every new software install.
-
Do a full ROS install:
$ sudo apt-get install ros-kinetic-desktop-full
-
Initialize rosdep:
$ sudo rosdep init $ rosdep update
-
At this point it is possible to add the ROS environment setup to the
~/.bashrc
file. But whether it is desirable is up to individual preference. Sourcing the ROSsetup.bash
file may cause conflicts with other python distributions or specific versions of OpenCV. It is up to the user to deal with these conflicts thereafter.The alternative is to source the ROS
setup.bash
file each time the workspace is required.In any case the following command adds the environment initialization to the
~/.bashrc
file.$ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc $ source ~/.bashrc
What the ~/.bashrc
file does is beyond the scope of this README, however it should be known that it is always sourced upon terminal initialization.
Note: The convenience script create_aliases.sh
creates a getros
alias that can be used to initialize ROS.
Even though ROS Kinetic comes with Gazebo 7, the ROS Gazebo control plugins have to be installed.
The following instructions have been taken from the Gazebo Sim website.
-
test if the stand-alone Gazebo works by launching it:
$ gazebo
-
Check to ensure that Gazebo has been installed via debian:
$ which gzserver /usr/bin/gzserver $ which gzclient /usr/bin/gzclient
If the printouts are not identical, uninstall all versions of Gazebo as well as ROS and reinstall ROS Kinetic from scratch.
-
Install the pre-built debians for ROS Gazebo Control packages:
$ sudo apt-get install ros-kinetic-gazebo-ros-pkgs ros-kinetic-gazebo-ros-control
Alternatively, install ROS Gazebo Control Packages from the source directly. This might help if certain libraries seem to be missing (especially materials or sensors).
-
Install the Gazebo7 development library:
$ sudo apt-get install -y libgazebo7-dev
-
Download the source code:
$ cd ~/catkin_ws/src $ git clone https://github.com/ros-simulation/gazebo_ros_pkgs.git -b kinetic-devel
-
Check if there are any missing dependencies using rosdep:
$ rosdep update $ rosdep check --from-paths . --ignore-src --rosdistro kinetic
-
If there are missing dependencies, they can be fixed using rosdep:
$ rosdep install --from-paths . --ignore-src --rosdistro kinetic -y
-
Build the packages by making the workspace:
$ cd ~/catkin_ws/ $ catkin_make
Check that ROS Gazebo works.
-
Source a test catkin workspace:
$ source ~/catkin_ws/devel/setup.bash
-
Start up the ROS master:
$ roscore
-
Rosrun the Gazebo ROS packages:
$ rosrun gazebo_ros gazebo
-
Check the rostopic list:
$ rostopic list /gazebo/link_states /gazebo/model_states /gazebo/parameter_descriptions /gazebo/parameter_updates /gazebo/set_link_state /gazebo/set_model_state
-
Verify that the Gazebo Services exist:
$ rosservice list /gazebo/apply_body_wrench /gazebo/apply_joint_effort /gazebo/clear_body_wrenches /gazebo/clear_joint_forces /gazebo/delete_model /gazebo/get_joint_properties /gazebo/get_link_properties /gazebo/get_link_state /gazebo/get_loggers /gazebo/get_model_properties /gazebo/get_model_state /gazebo/get_physics_properties /gazebo/get_world_properties /gazebo/pause_physics /gazebo/reset_simulation /gazebo/reset_world /gazebo/set_joint_properties /gazebo/set_link_properties /gazebo/set_link_state /gazebo/set_logger_level /gazebo/set_model_configuration /gazebo/set_model_state /gazebo/set_parameters /gazebo/set_physics_properties /gazebo/spawn_gazebo_model /gazebo/spawn_sdf_model /gazebo/spawn_urdf_model /gazebo/unpause_physics /rosout/get_loggers /rosout/set_logger_level