Ethercat for ROS indigo

Installation of ROS Indigo

Ros indigo is only supported on Ubuntu 14.04. Though Virtual machine can be used, it is recommended to have a complete installation on the machine.

Run the following commands to install ROS Indigo on ubuntu 14.04

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://ha.pool.sks-keyservers.net --recv-key 0xB01FA116

sudo apt-get update

sudo apt-get install ros-indigo-desktop-full

sudo rosdep init

rosdep update

echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc

source ~/.bashrc

Detailed information on these instructions is available at ROS website

Create a Workspace

Create a folder to store the codebase and initialize that folder as a catkin_workspace (catkin is a build system used by ROS)

mkdir -p ~/alligators_ws/src

cd ~/alligators_ws/src

catkin_init_workspace

catkin_create_pkg ethercat_example roscpp ethercat_hardware

cd ~/alligators_ws

catkin_make

echo "source ~/alligators_ws/devel/setup.bash" >> ~/.bashrc

source ~/.bashrc

Download sample code from here. Extract the downloaded file and replace ~/alligators_ws/src/example_ethercat with this package.

Ethercat Package

Install ethercat package

sudo apt-get update

sudo apt-get install ros-indigo-pr2-ethercat-drivers ros-indigo-pr2-ethercat

Find out the ethernet adapter name to which ethercat device is connected. This should be of format ‘ethX’ where X is an integer. ifconfig command can be used to query the available ethernet adapters in linux.

:~$ ifconfig -a
docker0   Link encap:Ethernet  HWaddr 56:84:7a:fc:a7:19  
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr a8:20:66:3e:2f:a4  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:5231 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5231 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:509642 (509.6 KB)  TX bytes:509642 (509.6 KB)

virbr0    Link encap:Ethernet  HWaddr 26:37:1a:bb:00:8d  
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 5c:96:9a:7e:22:6d  
          inet addr:10.0.0.87  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::5e96:9dff:fe7e:b26d/64 Scope:Link
          inet6 addr: 2601:98a:4000:20f5:5e96:9dff:fe7e:b26d/64 Scope:Global
          inet6 addr: 2601:98a:4000:20f5:81e1:66ca:2709:69f0/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:108776 errors:0 dropped:0 overruns:0 frame:214316
          TX packets:69526 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:122922125 (122.9 MB)  TX bytes:8517033 (8.5 MB)
          Interrupt:17

Open a terminal window and run roscore command

~:$roscore
... logging to /home/ninja/.ros/log/d0267b0e-0a1a-11e6-8140-5c969d7eb26d/roslaunch-ninja-MacBookPro-12106.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is 

Open another terminal window and run the following

sudo su
<<Enter Password>>

source /opt/ros/indigo/setup.bash

source ~/alligators_ws/devel/setup.bash

rosrun pr2_ethercat pr2_ethercat -i eth1 -x ~/alligators_ws/src/ethercat_example/description/robot.xml