Advertisement
Guest User

Untitled

a guest
May 30th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.37 KB | None | 0 0
  1. #!/bin/bash
  2. # The BSD License
  3. # Will install V-rep in /opt and configure the ros plugin
  4. # Olivier Kermorgant
  5. if [ "$SHELL" != "/bin/bash" ]; then echo "Run with bash \$ ${0}"; exit 1; fi
  6. vrep_version="3_4_0"
  7.  
  8. ros_distro="jade" # default version
  9.  
  10. version="$(lsb_release -sc)"
  11.  
  12. if [ "$version" = "xenial" ]
  13. then
  14.   ros_distro="kinetic"
  15. fi
  16.  
  17. echo "[Installing dependencies]"
  18. sudo apt-get install -y python-catkin-tools
  19. sudo apt-get install -y python-tempita
  20. sudo apt-get install -y xsltproc
  21.  
  22. echo "[Downloading V-REP]"
  23. #Use beta rev9 for 3.4.0 from
  24. #http://coppeliarobotics.com/files/tmp/V-REP_PRO_EDU_V3_4_0_rev9_Linux.tar.gz
  25. if [ ! -f V-REP_PRO_EDU_V${vrep_version}_Linux.tar.gz ]
  26. then
  27.     wget http://coppeliarobotics.com/files/V-REP_PRO_EDU_V${vrep_version}_Linux.tar.gz
  28. fi
  29. if [ ! -d V-REP_PRO_EDU_V${vrep_version}_Linux ]
  30. then
  31. #Extract beta rev9 version
  32.     tar -xzf V-REP_PRO_EDU_V${vrep_version}_rev9_Linux.tar.gz
  33. #   tar -xzf V-REP_PRO_EDU_V${vrep_version}_Linux.tar.gz
  34. fi
  35. #Extract additional archives if found (here just 7z)
  36. if [ -f $(ls -1 "${0#.sh}"*.7z | head -1 &>/dev/null) ]; then
  37.     for F in "${0#.sh}"*.7z; do 7z t "${F}" &>/dev/null && yes | 7z x "${F}"; done
  38. fi
  39. sudo rm -rf /opt/vrep
  40. sudo cp -R V-REP_PRO_EDU_V${vrep_version}_Linux /opt/vrep
  41. sudo chmod -R a+rwx /opt/vrep
  42. export VREP_ROOT=/opt/vrep
  43.  
  44. echo "[Configuring ROS plugin and interface]"
  45. cd /opt/vrep/programming/ros_packages/
  46. mkdir -p catkin/src
  47. chmod -R a+rx catkin
  48. #S#
  49. #Apparently these plugins are not there anymore
  50. #mv vrep_common catkin/src
  51. #mv vrep_plugin catkin/src
  52. #mv v_repExtRosInterface catkin/src
  53. #
  54. #cd catkin/src/vrep_plugin
  55. # update CMakeLists for OpenCV bug
  56. #sed -i 's/include_directories/find_package(OpenCV)\ninclude_directories/' CMakeLists.txt
  57. #sed -i 's/${catkin_INCLUDE_DIRS}/${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}/' CMakeLists.txt
  58. #E#
  59.  
  60. # init ROS interface
  61. #cd ..
  62. cd /opt/vrep/programming/ros_packages/catkin/src/
  63. git clone https://github.com/fferri/v_repExtRosInterface
  64. cd v_repExtRosInterface
  65. #cd ../v_repExtRosInterface
  66. mkdir -p external
  67. cd external
  68. git clone https://github.com/fferri/v_repStubsGen.git
  69. #ls -al v_repStubsGen
  70. export PYTHONPATH="$PYTHONPATH:$PWD"
  71.  
  72. echo "[Compiling ROS plugins]"
  73. #cd ../../..
  74. cd /opt/vrep/programming/ros_packages/catkin/
  75. #grep -R velodyne src/*
  76. catkin config --extend /opt/ros/${ros_distro} -i /opt/ros/${ros_distro} --install
  77. catkin clean -b --yes
  78. sudo -E bash -c 'VREP_ROOT=/opt/vrep && catkin build --pre-clean'
  79.  
  80. # copy plugin to vrep folder
  81. if [ -f /opt/vrep/libv_repExtRos.so ]
  82. then
  83.   sudo rm /opt/vrep/libv_repExtRos.so
  84. fi
  85. sudo ln -s /opt/vrep/programming/ros_packages/catkin/devel/.private/vrep_plugin/lib/libv_repExtRos.so /opt/vrep
  86.  
  87. # copy extension to vrep folder
  88. if [ -f /opt/vrep/libv_repExtRosInterface.so ]
  89. then
  90.    sudo rm /opt/vrep/libv_repExtRosInterface.so
  91. fi
  92. sudo ln -s /opt/vrep/programming/ros_packages/catkin/devel/.private/vrep_ros_interface/lib/libv_repExtRosInterface.so /opt/vrep
  93.  
  94. sudo chmod -R a+rx /opt/ros/
  95. sudo chmod -R a+rx /opt/vrep/
  96.  
  97. echo "[Creating V-REP launch file and shortcut]"
  98. launch_file=/opt/ros/${ros_distro}/share/vrep_plugin/vrep.launch
  99. if [ -f $launch_file ]
  100. then
  101.   sudo rm $launch_file
  102. fi
  103. sudo touch $launch_file
  104. sudo chmod a+rw $launch_file
  105. sudo cat>$launch_file <<EOL
  106. <?xml version="1.0"?>
  107. <launch>
  108.     <!-- Launch V-REP and roscore -->
  109.     <arg name="scene" default=""/>
  110.     <node name="vrep" pkg="vrep_plugin" type="vrep.py" respawn="false" output="screen" args="\$(arg scene)"/>  
  111.    
  112.     <!-- Launch check vitals to stop simulation if a topic is not published anymore -->
  113.     <arg name="topic" default="this_is_not_a_topic"/>
  114.     <arg name="delay" default="3"/>
  115.     <node name="check_vitals" pkg="vrep_plugin" type="check_vitals.py" output="screen" ns="vrep" args="\$(arg topic) \$(arg delay)"/>  
  116. </launch>
  117. EOL
  118.  
  119. # shortcut for V-REP launch script
  120. node_file=/opt/ros/${ros_distro}/share/vrep_plugin/vrep.py
  121. if [ -f $node_file ]
  122. then
  123.   sudo rm $node_file
  124. fi
  125. sudo touch $node_file
  126. sudo chmod a+rw $node_file
  127. sudo cat>$node_file <<EOL
  128. #!/usr/bin/env python
  129. from subprocess import call
  130. from sys import argv
  131. from os import chdir
  132. from os.path import abspath
  133. arg = ''
  134. if len(argv) > 1:
  135.     arg = abspath(argv[1])
  136. chdir('/opt/vrep')
  137. call(['bash','vrep.sh',arg])
  138. EOL
  139. sudo chmod a+x $node_file
  140.  
  141.  
  142. # check vitals
  143. node_file=/opt/ros/${ros_distro}/share/vrep_plugin/check_vitals.py
  144. if [ -f $node_file ]
  145. then
  146.   sudo rm $node_file
  147. fi
  148. sudo touch $node_file
  149. sudo chmod a+rw $node_file
  150. sudo cat>$node_file <<EOL
  151. #!/usr/bin/env python
  152. # -*- coding: utf-8 -*-
  153. #
  154. import rospy
  155. from vrep_common.srv import simRosStopSimulation, simRosStartSimulation
  156. import sys
  157. from commands import getoutput
  158.          
  159. if __name__ == "__main__":
  160.    
  161.     # no topic given, I am useless
  162.     if sys.argv[1] == 'this_is_not_a_topic':        
  163.         rospy.loginfo('check_vitals: No topic given, exit')
  164.         sys.exit(0)
  165.        
  166.     cmd_line = 'rostopic info ' + sys.argv[1]
  167.     msg_stop = 'check_vitals: Nobody publishing on ' + sys.argv[1] + ', stopping simulation'
  168.     msg_run = 'check_vitals: Got publisher on ' + sys.argv[1] + ', starting simulation'
  169.    
  170.     delay = int(sys.argv[2])
  171.    
  172.     rospy.init_node('check_vitals')
  173.    
  174.     # prepare to stop the simulation every <delay> sec
  175.     stopSim = rospy.ServiceProxy('/vrep/simRosStopSimulation', simRosStopSimulation)
  176.     startSim = rospy.ServiceProxy('/vrep/simRosStartSimulation', simRosStartSimulation)
  177.     startSim.wait_for_service()
  178.    
  179.     rate = rospy.Rate(1)
  180.    
  181.     alive = False
  182.     last_seen = 0
  183.        
  184.     while not rospy.is_shutdown():
  185.        
  186.         t = rospy.Time.now().to_sec()
  187.        
  188.         # get info on this topic
  189.         out = getoutput(cmd_line).splitlines()
  190.        
  191.         # Look for any publishers, will pass if topic does not exist (simulation not running)
  192.         for line in out:
  193.             if 'Publishers' in line and 'None' not in line:
  194.                 last_seen = t
  195.                
  196.         # check last seen
  197.         if t - last_seen > delay and alive:
  198.             # just died
  199.             alive = False
  200.             rospy.loginfo(msg_stop)
  201.             stopSim()
  202.         elif not alive and t - last_seen < delay:
  203.             # just popped
  204.             alive = True
  205.             rospy.loginfo(msg_run)
  206.             startSim()
  207.         rate.sleep()
  208. EOL
  209. sudo chmod a+x $node_file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement