ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Well, a colab notebook is basically a docker instance, so you can install ROS in a colab notebook!

What I did:

!sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

!sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

!sudo apt update

!sudo apt install ros-melodic-desktop-full

!pip install --extra-index-url https://rospypi.github.io/simple/ rospy

import rospy
### wait, we need a master:

!rm ros_start.sh
!printf -- '#!/bin/bash\n' > ros_start.sh
!printf -- 'source /opt/ros/melodic/setup.bash\n' >> ros_start.sh
!printf -- '/opt/ros/melodic/bin/roscore' >> ros_start.sh
!chmod +x ros_start.sh
!cat ros_start.sh

import subprocess
import os
prc = subprocess.Popen([os.getcwd()+"/ros_start.sh"])

###now we have a master!
rospy.get_published_topics()

Well, a colab notebook is basically a docker instance, so you can install ROS in a colab notebook!

What I did:

!sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

!sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

!sudo apt update

!sudo apt install ros-melodic-desktop-full

!pip install --extra-index-url https://rospypi.github.io/simple/ rospy

import rospy
### wait, we need a master:

!rm ros_start.sh
!printf -- '#!/bin/bash\n' > ros_start.sh
!printf -- 'source /opt/ros/melodic/setup.bash\n' >> ros_start.sh
!printf -- '/opt/ros/melodic/bin/roscore' >> ros_start.sh
!chmod +x ros_start.sh
!cat ros_start.sh

import subprocess
import os
prc = subprocess.Popen([os.getcwd()+"/ros_start.sh"])

###now we have a master!
rospy.get_published_topics()

Well, a colab notebook is basically a docker instance, so you can install ROS in a colab notebook!

What I did:

!sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

!sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

!sudo apt update

!sudo apt install ros-melodic-desktop-full

!pip install --extra-index-url https://rospypi.github.io/simple/ rospy

import rospy
### wait, we need a master:

!printf -- '#!/bin/bash\n' > ros_start.sh
!printf -- 'source /opt/ros/melodic/setup.bash\n' >> ros_start.sh
!printf -- '/opt/ros/melodic/bin/roscore' >> ros_start.sh
!chmod +x ros_start.sh
!cat ros_start.sh

import subprocess
import os
prc = subprocess.Popen([os.getcwd()+"/ros_start.sh"])
###now

Here you need to wait a bit since subprocess is asynchronous and the master will take some time to load.

###when we have a master!
master the following line should work.
rospy.get_published_topics()

Here is the gist for it, if you want to try it out yourself. https://gist.github.com/frederico-klein/685a0697f5f93e3b20415852154fac51

Well, a colab notebook is basically a docker instance, so you can install ROS in a colab notebook!

What I did:

!sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

!sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

!sudo apt update

!sudo apt install ros-melodic-desktop-full

!pip install --extra-index-url https://rospypi.github.io/simple/ rospy

import rospy
### wait, we need a master:

!printf -- '#!/bin/bash\n' > ros_start.sh
!printf -- 'source /opt/ros/melodic/setup.bash\n' >> ros_start.sh
!printf -- '/opt/ros/melodic/bin/roscore' >> ros_start.sh
!chmod +x ros_start.sh
!cat ros_start.sh

import subprocess
import os
prc = subprocess.Popen([os.getcwd()+"/ros_start.sh"])

Here (as pointed out by shandilya1998 and Gustavo Lima) you need to wait a bit since subprocess is asynchronous and the master will take some time to load.

###when we have a master the following line should work.
rospy.get_published_topics()

Here is the gist for it, if you want to try it out yourself. https://gist.github.com/frederico-klein/685a0697f5f93e3b20415852154fac51