Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hrpsys_config.py in seq walking sample. #79

Merged
merged 3 commits into from
Apr 30, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 25 additions & 56 deletions samples/samplerobot-walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,36 @@
$ rosrun hrpsys samplerobot-walk.py

"""
import imp, sys, os

# set path to hrpsys to get import rpy, see <hrpsys>/test/test-samplerobot.py for using HrpsysConfigurator
try:
imp.find_module('hrpsys') # catkin installed
sys.path.append(imp.find_module('hrpsys')[1]) # set path to hrpsys
except: # rosbuild installed
import rospkg
rp = rospkg.RosPack()
sys.path.append(rp.get_path('hrpsys')+'/lib/python2.7/dist-packages/hrpsys')
sys.path.append(rp.get_path('openrtm_aist_python')+'/lib/python2.7/dist-packages')



import rtm

from rtm import *
from OpenHRP import *

def connectComps():
connectPorts(bridge.port("q"), seq.port("qInit"))
#
connectPorts(seq.port("qRef"), hgc.port("qIn"))
#

def activateComps():
rtm.serializeComponents([bridge, seq])
seq.start()

def createComps():
global bridge, seq, seq_svc, hgc

bridge = findRTC("SampleRobot(Robot)0")

ms.load("SequencePlayer")
seq = ms.create("SequencePlayer", "seq")
seq_svc = narrow(seq.service("service0"),"SequencePlayerService")

hgc = findRTC("HGcontroller0")

def init():
global ms

ms = rtm.findRTCmanager()

print "creating components"
createComps()

print "connecting components"
connectComps()

print "activating components"
activateComps()
print "initialized successfully"
pkg = 'hrpsys'
import imp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not delete line for catkin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are copied from hrpsys_tools_config.py:
https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_tools/scripts/hrpsys_tools_config.py

I thought hrpsys_tools_config.py worked on both rosbuild and catkin.
Is this correct?

sensor_ros_bridge_connect.py has another way to import hrpsys_config.py.
https://github.com/start-jsk/rtmros_common/blob/master/hrpsys_ros_bridge/scripts/sensor_ros_bridge_connect.py

I'd like to know which is the best way to import hrpsys_config.py.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/start-jsk/rtmros_common/blob/9c30250a5df5793dd9df0b161fc7642835755b67/hrpsys_ros_bridge/scripts/hrpsys_dashboard is the good example of writing python code that works on both rosmake and catkin.

the example you mentioned had some trouble on same situation (sorry I can't point out but it actually have problem)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:
imp.find_module(pkg)
except:
import roslib
roslib.load_manifest(pkg)

from hrpsys.hrpsys_config import *
import OpenHRP

def getRTCList ():
return [
['seq', "SequencePlayer"],
['sh', "StateHolder"],
['fk', "ForwardKinematics"]
]

def init ():
global hcf
hcf = HrpsysConfigurator()
hcf.getRTCList = getRTCList
hcf.init ("SampleRobot(Robot)0")

def loadPattern(basename, tm=1.0):
seq_svc.loadPattern(basename, tm)
seq_svc.waitInterpolation()
hcf.seq_svc.loadPattern(basename, tm)
hcf.seq_svc.waitInterpolation()

if __name__ == '__main__':
initCORBA()
init()

from subprocess import check_output
Expand Down