Skip to content

Commit d07b31e

Browse files
committed
[hrpsys_choreonoid][hrpsys_choreonoid_tutorials] add HRP3HAND for HRP2JSKNT*
1 parent 5fe6f66 commit d07b31e

File tree

10 files changed

+182
-16
lines changed

10 files changed

+182
-16
lines changed

hrpsys_choreonoid/iob/RobotHardware_choreonoid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static const char* robothardware_choreonoid_spec[] =
2828
};
2929
// </rtc-template>
3030

31-
extern RobotHardware_choreonoid *self_ptr;
31+
extern RTC::DataFlowComponentBase *self_ptr;
3232
extern void iob_update();
3333
extern void iob_finish();
3434
extern void iob_set_torque_limit(std::vector<double> &vec);

hrpsys_choreonoid/iob/iob.cpp

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <cstdlib>
44
#include <cstring>
55
#include <vector>
6-
#include "iob.h"
76

87
#include <stdio.h>
98

@@ -16,8 +15,14 @@
1615
#include <rtm/idl/BasicDataTypeSkel.h>
1716
#include <hrpModel/ModelLoaderUtil.h>
1817
#include <hrpModel/Sensor.h>
18+
#include <rtm/idl/BasicDataType.hh>
19+
#include <rtm/idl/ExtendedDataTypes.hh>
20+
21+
#if defined IOB_NAMESPACE
22+
namespace IOB_NAMESPACE {
23+
#endif
1924

20-
#include "RobotHardware_choreonoid.h"
25+
#include "iob.h"
2126

2227
static std::vector<double> command;
2328
static std::vector<double> act_angle;
@@ -39,8 +44,6 @@ static timespec g_ts;
3944
static long g_period_ns=5000000;
4045
static std::vector<bool> isPosTq;
4146

42-
Time iob_time;
43-
4447
#define FORCE_AVERAGE 8
4548
#define TORQUE_AVERAGE 2
4649

@@ -57,7 +60,9 @@ static std::vector<std::vector<double> > torque_queue;
5760

5861
using namespace RTC;
5962

60-
RobotHardware_choreonoid *self_ptr;
63+
Time iob_time;
64+
65+
RTC::DataFlowComponentBase *self_ptr;
6166

6267
//* *//
6368
static TimedDoubleSeq m_angleIn;
@@ -100,6 +105,7 @@ static std::vector<double> Pgain_orig, Dgain_orig;
100105
static std::vector<double> tlimit;
101106
static size_t dof, loop;
102107
static unsigned int m_debugLevel;
108+
static bool initial_p=true;
103109

104110
static int iob_step;
105111
static int iob_nstep;
@@ -189,6 +195,23 @@ int set_number_of_joints(int num)
189195
for (int j = 0; j < TORQUE_AVERAGE; j++) {
190196
torque_queue[j].resize(num);
191197
}
198+
199+
dof = num;
200+
m_torqueOut.data.length(dof);
201+
m_angleIn.data.length(dof);
202+
qold.resize(dof);
203+
qold_ref.resize(dof);
204+
tqold.resize(dof);
205+
tqold_ref.resize(dof);
206+
Pgain.resize(dof);
207+
Dgain.resize(dof);
208+
tqPgain.resize(dof);
209+
tqDgain.resize(dof);
210+
initial_Pgain.resize(dof);
211+
initial_Dgain.resize(dof);
212+
initial_tqPgain.resize(dof);
213+
initial_tqDgain.resize(dof);
214+
192215
return TRUE;
193216
}
194217

@@ -667,6 +690,8 @@ int open_iob(void)
667690
}
668691
}
669692

693+
readGainFile();
694+
670695
std::cerr << "choreonoid IOB is opened" << std::endl;
671696
return TRUE;
672697
}
@@ -678,10 +703,18 @@ void iob_update(void)
678703
{
679704
if(ip_angleIn->isNew()) {
680705
ip_angleIn->read();
681-
if (dof == 0) {
682-
dof = m_angleIn.data.length();
683-
m_torqueOut.data.length(dof);
684-
readGainFile();
706+
if (initial_p){
707+
if (dof != m_angleIn.data.length()) {
708+
dof = m_angleIn.data.length();
709+
m_torqueOut.data.length(dof);
710+
readGainFile();
711+
}
712+
// initialize angleRef, old_ref and old with angle
713+
for(int i = 0; i < dof; ++i) {
714+
command[i] = qold_ref[i] = qold[i] = m_angleIn.data[i];
715+
com_torque[i] = tqold_ref[i] = tqold[i] = 0/*act_torque[i]*/;
716+
}
717+
initial_p = false;
685718
}
686719
for(int i = 0; i < m_angleIn.data.length() && i < dof; i++) {
687720
act_angle[i] = m_angleIn.data[i];
@@ -917,11 +950,6 @@ static void readGainFile()
917950
} else {
918951
std::cerr << "[iob] Gain file [" << gain_fname << "] not opened" << std::endl;
919952
}
920-
// initialize angleRef, old_ref and old with angle
921-
for(int i = 0; i < dof; ++i) {
922-
command[i] = qold_ref[i] = qold[i] = m_angleIn.data[i];
923-
com_torque[i] = tqold_ref[i] = tqold[i] = 0/*act_torque[i]*/;
924-
}
925953
}
926954

927955
int close_iob(void)
@@ -1290,4 +1318,6 @@ int read_digital_output(char *doutput)
12901318
return FALSE;
12911319
}
12921320

1293-
1321+
#if defined IOB_NAMESPACE
1322+
}
1323+
#endif

hrpsys_choreonoid_tutorials/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ else()
3535
set (HRP2_MODELS_DIR ${hrp2_models_SOURCE_PREFIX})
3636
endif()
3737

38+
find_package(jsk_hrp2_ros_bridge QUIET)
39+
if(NOT "${jsk_hrp2_ros_bridge_FOUND}")
40+
string(ASCII 27 Esc)
41+
message(WARNING "${Esc}[1;33mPackage jsk_hrp2_ros_bridge is not found, if you have right to access them please include source code in catkin workspace${Esc}[m")
42+
else()
43+
set (JSK_HRP2_ROS_BRIDGE_DIR ${jsk_hrp2_ros_bridge_SOURCE_PREFIX})
44+
endif()
45+
3846
################################
3947
## compile_openhrp_model
4048
## Generate OpenHRP3 .xml and .conf file.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
##
2+
name-server = localhost:15005
3+
##
4+
## PD Controller
5+
## in: angleRef, angle
6+
## out: torque
7+
##
8+
in-port = tauIn:R_THUMBCM_Y,R_THUMBCM_P,R_INDEXMP_R,R_INDEXMP_P,R_INDEXPIP_R,R_MIDDLEPIP_R,L_THUMBCM_Y,L_THUMBCM_P,L_INDEXMP_R,L_INDEXMP_P,L_INDEXPIP_R,L_MIDDLEPIP_R:JOINT_TORQUE
9+
out-port = angleOut:R_THUMBCM_Y,R_THUMBCM_P,R_INDEXMP_R,R_INDEXMP_P,R_INDEXPIP_R,R_MIDDLEPIP_R,L_THUMBCM_Y,L_THUMBCM_P,L_INDEXMP_R,L_INDEXMP_P,L_INDEXPIP_R,L_MIDDLEPIP_R:JOINT_VALUE
10+
out-port = qvel:R_THUMBCM_Y,R_THUMBCM_P,R_INDEXMP_R,R_INDEXMP_P,R_INDEXPIP_R,R_MIDDLEPIP_R,L_THUMBCM_Y,L_THUMBCM_P,L_INDEXMP_R,L_INDEXMP_P,L_INDEXPIP_R,L_MIDDLEPIP_R:JOINT_VELOCITY
11+
out-port = torque:R_THUMBCM_Y,R_THUMBCM_P,R_INDEXMP_R,R_INDEXMP_P,R_INDEXPIP_R,R_MIDDLEPIP_R,L_THUMBCM_Y,L_THUMBCM_P,L_INDEXMP_R,L_INDEXMP_P,L_INDEXPIP_R,L_MIDDLEPIP_R:JOINT_TORQUE
12+
# out-port = ddq:JOINT_ACCELERATION
13+
connection = tauIn:HRP3HandController_choreonoid0:torqueOut
14+
connection = angleOut:HRP3HandController_choreonoid0:angleIn
15+
connection = qvel:HRP3HandController_choreonoid0:qvel_sim
16+
connection = torque:HRP3HandController_choreonoid0:torque_sim

hrpsys_choreonoid_tutorials/config/HRP2JSKNTS_LOAD_OBJ.cnoid.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ items:
6565
AutoConnect: false
6666
InstanceName: HRP2JSKNTS(Robot)0
6767
bodyPeriodicRate: 0.004
68+
-
69+
id: 6
70+
name: "BodyRTC_hand"
71+
plugin: OpenRTM
72+
class: BodyRTCItem
73+
data:
74+
isImmediateMode: true
75+
moduleName: "@JSK_HRP2_ROS_BRIDGE_DIR@/lib/choreonoid/HRP3HandController_choreonoid"
76+
confFileName: "@JVRC_CONF_DIRECTORY@/BodyRTC_HRP3HAND.RH.conf"
77+
configurationMode: Use Configuration File
78+
AutoConnect: false
79+
InstanceName: HRP3HAND(Robot)0
80+
bodyPeriodicRate: 0.004
6881
-
6982
id: 4
7083
name: "add_objects.py"

hrpsys_choreonoid_tutorials/config/HRP2JSKNT_LOAD_OBJ.cnoid.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ items:
6565
AutoConnect: false
6666
InstanceName: HRP2JSKNT(Robot)0
6767
bodyPeriodicRate: 0.004
68+
-
69+
id: 6
70+
name: "BodyRTC_hand"
71+
plugin: OpenRTM
72+
class: BodyRTCItem
73+
data:
74+
isImmediateMode: true
75+
moduleName: "@JSK_HRP2_ROS_BRIDGE_DIR@/lib/choreonoid/HRP3HandController_choreonoid"
76+
confFileName: "@JVRC_CONF_DIRECTORY@/BodyRTC_HRP3HAND.RH.conf"
77+
configurationMode: Use Configuration File
78+
AutoConnect: false
79+
InstanceName: HRP3HAND(Robot)0
80+
bodyPeriodicRate: 0.004
6881
-
6982
id: 4
7083
name: "add_objects.py"

hrpsys_choreonoid_tutorials/launch/hrp2jsknt_choreonoid.launch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
<arg name="HRPSYS_PY_NAME" value="hrp2_rh_setup.py" />
1616
<arg name="CONTROLLER_CONFIG" value="$(find hrpsys_ros_bridge_tutorials)/models/HRP2JSKNT_controller_config.yaml" />
1717
<arg name="CUSTOMIZER_CONF_FILE" value="$(find hrpsys_choreonoid_tutorials)/config/HRP2JSKNTCustomizer.yaml" />
18+
<arg name="hrpsys_opt_rtc_config_args" value='-o "example.HRP3HandController_choreonoid.config_file:$(find hrpsys_ros_bridge_tutorials)/models/HRP2JSKNT.conf" -o "example.HRP3HandController_choreonoid.pdgains_sim_file_name:$(find jsk_hrp2_ros_bridge)/rtc/HRP3HandController/HRP3HAND.PDgains.dat"'/>
1819
</include>
1920

21+
<!-- HRP3HANDControllerServiceROSBridge -->
22+
<env name="LANG" value="C" />
23+
<env name="ORBgiopMaxMsgSize" value="2147483648" />
24+
<arg name="nameserver" default="localhost" />
25+
<arg name="corbaport" default="15005" />
26+
<arg name="managerport" default="2810" />
27+
<env name="RTCTREE_NAMESERVERS" value="$(arg nameserver):$(arg corbaport)" />
28+
<env name="RTC_CONNECTION_CHECK_ONCE" value="true" />
29+
30+
<node pkg="jsk_hrp2_ros_bridge" name="HRP3HandControllerServiceROSBridge" type="HRP3HandControllerServiceROSBridgeComp"
31+
output="screen" args='-o "corba.master_manager:$(arg nameserver):$(arg managerport)" -o "corba.nameservers:$(arg nameserver):$(arg corbaport)" -o "naming.formats:%n.rtc" -o "exec_cxt.periodic.type:PeriodicExecutionContext" -o "exec_cxt.periodic.rate:2000" -o "logger.file_name:/tmp/rtc%p.log"' />
32+
<rtconnect from="HRP3HandControllerServiceROSBridge.rtc:HRP3HandControllerService" to="HRP3HandController_choreonoid0.rtc:HRP3HandControllerService" subscription_type="new"/>
33+
<rtactivate component="HRP3HandControllerServiceROSBridge.rtc" />
34+
<node name="rtmlaunch_hrp2jsknt_choreonoid" pkg="openrtm_tools" type="rtmlaunch.py" args="$(find hrpsys_choreonoid_tutorials)/launch/hrp2jsknt_choreonoid.launch" output="screen"/>
35+
2036
</launch>

hrpsys_choreonoid_tutorials/launch/hrp2jsknts_choreonoid.launch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@
1515
<arg name="HRPSYS_PY_NAME" value="hrp2_rh_setup.py" />
1616
<arg name="CONTROLLER_CONFIG" value="$(find hrpsys_ros_bridge_tutorials)/models/HRP2JSKNTS_controller_config.yaml" />
1717
<arg name="CUSTOMIZER_CONF_FILE" value="$(find hrpsys_choreonoid_tutorials)/config/HRP2JSKNTSCustomizer.yaml" />
18+
<arg name="hrpsys_opt_rtc_config_args" value='-o "example.HRP3HandController_choreonoid.config_file:$(find hrpsys_ros_bridge_tutorials)/models/HRP2JSKNT.conf" -o "example.HRP3HandController_choreonoid.pdgains_sim_file_name:$(find jsk_hrp2_ros_bridge)/rtc/HRP3HandController/HRP3HAND.PDgains.dat"'/>
1819
</include>
1920

21+
<!-- HRP3HANDControllerServiceROSBridge -->
22+
<env name="LANG" value="C" />
23+
<env name="ORBgiopMaxMsgSize" value="2147483648" />
24+
<arg name="nameserver" default="localhost" />
25+
<arg name="corbaport" default="15005" />
26+
<arg name="managerport" default="2810" />
27+
<env name="RTCTREE_NAMESERVERS" value="$(arg nameserver):$(arg corbaport)" />
28+
<env name="RTC_CONNECTION_CHECK_ONCE" value="true" />
29+
30+
<node pkg="jsk_hrp2_ros_bridge" name="HRP3HandControllerServiceROSBridge" type="HRP3HandControllerServiceROSBridgeComp"
31+
output="screen" args='-o "corba.master_manager:$(arg nameserver):$(arg managerport)" -o "corba.nameservers:$(arg nameserver):$(arg corbaport)" -o "naming.formats:%n.rtc" -o "exec_cxt.periodic.type:PeriodicExecutionContext" -o "exec_cxt.periodic.rate:2000" -o "logger.file_name:/tmp/rtc%p.log"' />
32+
<rtconnect from="HRP3HandControllerServiceROSBridge.rtc:HRP3HandControllerService" to="HRP3HandController_choreonoid0.rtc:HRP3HandControllerService" subscription_type="new"/>
33+
<rtactivate component="HRP3HandControllerServiceROSBridge.rtc" />
34+
<node name="rtmlaunch_hrp2jsknts_choreonoid" pkg="openrtm_tools" type="rtmlaunch.py" args="$(find hrpsys_choreonoid_tutorials)/launch/hrp2jsknts_choreonoid.launch" output="screen"/>
35+
2036
</launch>

hrpsys_choreonoid_tutorials/launch/robot_choreonoid.launch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<arg name="USE_VISION" default="true" />
88
<arg name="GUI" default="true" />
99
<arg name="hrpsys_precreate_rtc" default=""/>
10+
<arg name="hrpsys_opt_rtc_config_args" default=""/>
1011
<arg name="LAUNCH_FOOTCOORDS" default="true" />
1112

1213
<arg name="CHOREONOID_ROBOT" default="JAXON_RED"/>
@@ -49,6 +50,7 @@
4950
<arg name="REALTIME" value="$(arg REALTIME)" />
5051
<arg name="GUI" value="$(arg GUI)" />
5152
<arg name="hrpsys_precreate_rtc" value="$(arg hrpsys_precreate_rtc)" />
53+
<arg name="hrpsys_opt_rtc_config_args" value="$(arg hrpsys_opt_rtc_config_args)"/>
5254
<arg name="CONNECT_CONSTRAINT_FORCE_LOGGER_PORTS" default="$(arg CONNECT_CONSTRAINT_FORCE_LOGGER_PORTS)"/>
5355
</include>
5456
<!-- ros_bridge -->

hrpsys_choreonoid_tutorials/scripts/hrp2_rh_setup.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
from hrpsys_ros_bridge_tutorials.hrp2_hrpsys_config import *
44

55
class JSKHRP2ChoreonoidHrpsysConfigurator(JSKHRP2HrpsysConfigurator):
6+
def getRTCList (self):
7+
rtclist = JSKHRP2HrpsysConfigurator.getRTCList(self)
8+
if self.ROBOT_NAME.find("HRP2JSKNT") != -1:
9+
if ['hc', "HRP3HandController"] in rtclist:
10+
rtclist.remove(['hc', "HRP3HandController"]) #HRP3HandController is created by choreonoid like RobotHardware
11+
return rtclist
12+
13+
def getRTCInstanceList(self, verbose=True):
14+
ret = JSKHRP2HrpsysConfigurator.getRTCInstanceList(self, verbose)
15+
if self.ROBOT_NAME.find("HRP2JSKNT") != -1:
16+
ret.append(self.hc)
17+
return ret
18+
619
def waitForRobotHardware(self, robotname="Robot"):
720
'''!@brief
821
Wait for RobotHardware is exists and activated.
@@ -50,6 +63,45 @@ def waitForRobotHardware(self, robotname="Robot"):
5063

5164
print(self.configurator_name + "findComps -> %s : %s isActive? = %s " % (robotname, self.rh_choreonoid, self.rh_choreonoid.isActive()))
5265

66+
def waitForHRP3HandController(self, robotname="Robot"):
67+
'''!@brief
68+
Wait for HRP3HandController is exists and activated.
69+
70+
@param robotname str: name of RobotHardware component.
71+
'''
72+
self.hc = None
73+
timeout_count = 0
74+
# wait for simulator or HRP3HANDController setup which sometime takes a long time
75+
while self.hc == None and timeout_count < 10: # <- time out limit
76+
if timeout_count > 0: # do not sleep initial loop
77+
time.sleep(1);
78+
self.hc = rtm.findRTC("HRP3HandController_choreonoid0")
79+
print(self.configurator_name + "wait for %s : %s ( timeout %d < 10)" % ( "HRP3Hand", self.hc, timeout_count))
80+
if self.hc and self.hc.isActive() == None: # just in case hc is not ready...
81+
self.hc = None
82+
timeout_count += 1
83+
84+
if not self.hc:
85+
print(self.configurator_name + "Could not find HRP3HandController_choreonoid0")
86+
if self.ms:
87+
print(self.configurator_name + "Candidates are .... " + str([x.name() for x in self.ms.get_components()]))
88+
print(self.configurator_name + "Exitting.... " + robotname)
89+
exit(1)
90+
91+
print(self.configurator_name + "findComps -> HRP3HandController_choreonoid0 : %s isActive? = %s " % (self.hc, self.hc.isActive()))
92+
93+
def waitForRTCManagerAndRobotHardware(self, robotname="Robot", managerhost=nshost):
94+
'''!@brief
95+
Wait for both RTC Manager (waitForRTCManager()) and RobotHardware (waitForRobotHardware()) and HRP3HandController (waitForHRP3HandController)
96+
@param managerhost str: name of host computer that manager is running
97+
@param robotname str: name of RobotHardware component.
98+
'''
99+
self.waitForRTCManager(managerhost)
100+
self.waitForRobotHardware(robotname)
101+
if self.ROBOT_NAME.find("HRP2JSKNT") != -1:
102+
self.waitForHRP3HandController(robotname)
103+
self.checkSimulationMode()
104+
53105
def activateComps(self):
54106
stash_rh = self.rh
55107
self.rh = self.rh_choreonoid

0 commit comments

Comments
 (0)