(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

How to Automatically Run ps3joy as a daemon

Description:

Tutorial Level:

This tutorials shows how to run ps3joy as daemon, so that you don't have to manually invoke ps3joy.py.

Contents

  1. setup udev

  Show EOL distros: 

Below shows the ps3joy daemon launcher file

### BEGIN INIT INFO
# Provides:          ps3joy
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts instance of ps3joy.py
# Description:       starts instance of pd3joy.py
### END INIT INFO

############### EDIT ME ##################

#APP_PATH=""

. /opt/ros/electric/setup.sh
export ROS_HOME=/root

# path to daemon
DAEMON=`rospack find ps3joy`/ps3joy.py

# startup args
DAEMON_OPTS="--inactivity-timeout=900 --redirect-output=/var/log/ps3joy.log"

# script name
NAME=ps3joy

# app name
DESC=ps3joy

RUN_AS=root

PID_FILE=/var/run/ps3joy.pid

############### END EDIT ME ##################

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "

        start-stop-daemon -c $RUN_AS --start --background --pidfile $PID_FILE  --make-pidfile -a $DAEMON -- $DAEMON_OPTS

        if [ $? ]; then
            echo "[OK]"
        else
            echo "[FAILED]"
        fi

        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --pidfile $PID_FILE
        if [ $? ]; then
            echo "[OK]"
        else
            echo "[FAILED]"
        fi
        ;;

  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --oknodo --pidfile $PID_FILE
        sleep 1
        start-stop-daemon -c $RUN_AS --start --background --pidfile $PID_FILE  --make-pidfile -a $DAEMON -- $DAEMON_OPTS
        if [ $? ]; then
            echo "[OK]"
        else
            echo "[FAILED]"
        fi

        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

Below shows the ps3joy daemon launcher file

### BEGIN INIT INFO
# Provides:          ps3joy
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts instance of ps3joy.py
# Description:       starts instance of pd3joy.py
### END INIT INFO

############### EDIT ME ##################

#APP_PATH=""

. /opt/ros/electric/setup.sh
export ROS_HOME=/root

# path to daemon
DAEMON=/opt/ros/hydro/lib/ps3joy/ps3joy.py

# startup args
DAEMON_OPTS="--inactivity-timeout=900 --redirect-output=/var/log/ps3joy.log"

# script name
NAME=ps3joy

# app name
DESC=ps3joy

RUN_AS=root

PID_FILE=/var/run/ps3joy.pid

############### END EDIT ME ##################

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "

        start-stop-daemon -c $RUN_AS --start --background --pidfile $PID_FILE  --make-pidfile -a $DAEMON -- $DAEMON_OPTS

        if [ $? ]; then
            echo "[OK]"
        else
            echo "[FAILED]"
        fi

        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --pidfile $PID_FILE
        if [ $? ]; then
            echo "[OK]"
        else
            echo "[FAILED]"
        fi
        ;;

  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --oknodo --pidfile $PID_FILE
        sleep 1
        start-stop-daemon -c $RUN_AS --start --background --pidfile $PID_FILE  --make-pidfile -a $DAEMON -- $DAEMON_OPTS
        if [ $? ]; then
            echo "[OK]"
        else
            echo "[FAILED]"
        fi

        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

To install

sudo update-rc.d ps3joy defaults 99 99

, To uninstall,

sudo update-rc.d -f ps3joy remove

setup udev

You need to write udev rule for ps3 to see always the device file with the same name. Please copy the following file at /etc/udev/rules.d/73-joy-aliases.rules.

SUBSYSTEMS=="input", KERNEL=="js[0-9]*", ATTRS{name}=="Sony Playstation SixAxis/DS3", SYMLINK+="input/ps3joy"

Please restart udev.

sudo service udev restart

And you can see ps3 at /dev/input/ps3joy

Wiki: ps3joy/Tutorials/Running ps3joy.py as daemon (last edited 2014-08-01 09:30:39 by ryohei)