Skip to content

Commit

Permalink
Merge pull request #356 from ipa-nhg/MimicPy
Browse files Browse the repository at this point in the history
HotFix: readded python node for mimic
  • Loading branch information
Benjamin Maidel authored Aug 22, 2017
2 parents a175a93 + e27c9ef commit c299763
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cob_mimic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ install(PROGRAMS src/test_mimic.py
install(DIRECTORY common
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)

install(PROGRAMS src/mimic_node.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}/src
)
94 changes: 94 additions & 0 deletions cob_mimic/src/mimic_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python
#
# Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import vlc
import threading

import roslib
import rospy
import actionlib

from cob_mimic.srv import *
from cob_mimic.msg import *

class Mimic:
def service_cb(self, req):
success = self.set_mimic(req.mimic, req.speed, req.repeat)
return SetMimicResponse(success, "")

def action_cb(self, goal):
if self.set_mimic(goal.mimic, goal.speed, goal.repeat):
self._as.set_succeeded()
else:
self._as.set_aborted()

def set_mimic(self, mimic, speed, repeat):
rospy.loginfo("Mimic: %s", mimic)
file_location = '/tmp/mimic/' + mimic + '.mp4'
if(not os.path.isfile(file_location)):
rospy.logerror("File not found: %s", file_location)
return False

# repeat cannot be 0
repeat = max (1, repeat)

for i in range(0, repeat):
rospy.loginfo("Repeat: %s, Mimic: %s", repeat, mimic)
command = "export DISPLAY=:0 && vlc --video-wallpaper --video-filter 'rotate{angle=%d}' --vout glx --one-instance --playlist-enqueue --no-video-title-show --rate %f %s vlc://quit" % (self.rotation, speed, file_location)
os.system(command)

return True

def defaultMimic(self):
file_location = '/tmp/mimic/' + self.default_mimic + '.mp4'
if not os.path.isfile(file_location):
rospy.logerror("File not found: %s", file_location)
return

while not rospy.is_shutdown():
command = "export DISPLAY=:0 && vlc --video-wallpaper --video-filter 'rotate{angle=%d}' --vout glx --loop --one-instance --playlist-enqueue --no-video-title-show --rate %f %s vlc://quit" % (self.rotation, self.default_speed, file_location)
os.system(command)

def main(self):
self.default_speed = 1.0
self.default_mimic = "default"
self.rotation = rospy.get_param('~rotation', 0)

# copy all videos to /tmp
rospy.loginfo("copying all mimic files to /tmp/mimic...")
file_location = roslib.packages.get_pkg_dir('cob_mimic') + '/common/*.mp4'
os.system("mkdir -p /tmp/mimic")
os.system("cp " + file_location + " /tmp/mimic")
rospy.loginfo("...copied all mimic files to /tmp/mimic")

self._ss = rospy.Service('~set_mimic', SetMimic, self.service_cb)
self._as = actionlib.SimpleActionServer('~set_mimic', cob_mimic.msg.SetMimicAction, execute_cb=self.action_cb, auto_start = False)
self._as.start()

rospy.spin()



if __name__ == "__main__":
rospy.init_node('mimic')
try:
mimic = Mimic()
mimic.main()
except (rospy.ROSInterruptException, KeyboardInterrupt, SystemExit) as e:
rospy.loginfo('Exiting: ' + str(e))
pass

0 comments on commit c299763

Please sign in to comment.