2 #include <hrpModel/Sensor.h> 14 "implementation_id",
"BodyRTC",
15 "type_name",
"BodyRTC",
16 "description",
"BodyRTC component",
19 "category",
"Generic",
20 "activity_type",
"DataFlowComponent",
23 "lang_type",
"compile",
32 m_RobotHardwareServicePort(
"RobotHardwareService"),
33 m_resetPosition(true),
64 #define DEFAULT_ANGLE_ERROR_LIMIT 0.2 // [rad] // copied from robot.cpp 66 std::cout <<
"BodyRTC::setup(), numJoints = " <<
numJoints() << std::endl;
86 std::string &
name, std::string &type,
87 std::vector<std::string> &elements)
89 std::string::size_type colon = 0,
start=0;
90 colon = config.find(
':',
start);
91 if (colon == std::string::npos){
92 std::cerr <<
"can't find the first separator in [" << config <<
"]" 96 name = config.substr(
start, colon);
98 colon = config.find(
':',
start);
99 if (colon == std::string::npos){
100 type = config.substr(
start);
103 std::string elist = config.substr(
start, colon-
start);
104 std::string::size_type comma;
106 comma = elist.find(
',',
start);
107 while (comma != std::string::npos){
108 std::string e = elist.substr(
start, comma-
start);
109 elements.push_back(e);
111 comma = elist.find(
',',
start);
113 elements.push_back(elist.substr(
start));
115 type = config.substr(
start);
119 std::vector<hrp::Link *> &
joints)
121 if (elements.size() == 0){
123 joints.push_back(body->
joint(
i));
126 for (
size_t i=0;
i<elements.size();
i++){
131 std::cerr <<
"can't find a joint(" << elements[i] <<
")" 143 std::vector<std::string> elements;
145 if (type ==
"JOINT_VALUE"){
146 std::vector<hrp::Link *>
joints;
151 }
else if(type ==
"JOINT_VELOCITY"){
152 std::vector<hrp::Link *>
joints;
157 }
else if(type ==
"JOINT_ACCELERATION"){
158 std::vector<hrp::Link *>
joints;
163 }
else if(type ==
"JOINT_TORQUE"){
164 std::vector<hrp::Link *>
joints;
169 }
else if(type ==
"EXTERNAL_FORCE"){
170 std::cout <<
"EXTERNAL_FORCE is not implemented yet" << std::endl;
171 }
else if(type ==
"ABS_TRANSFORM"){
172 std::vector<hrp::Link *>
joints;
173 if (
getJointList(
this, elements, joints) && joints.size() == 1){
176 }
else if (elements.size() == 1) {
183 std::cerr <<
"can't find a link(or a sensor)(" << elements[0] <<
")" 186 }
else if(type ==
"ABS_VELOCITY"){
187 std::vector<hrp::Link *>
joints;
188 if (
getJointList(
this, elements, joints) && joints.size() == 1){
192 }
else if(type ==
"ABS_ACCELERATION"){
193 std::vector<hrp::Link *>
joints;
194 if (
getJointList(
this, elements, joints) && joints.size() == 1){
198 }
else if(type ==
"FRAME_RATE"){
199 VisionSensor *s = this->sensor<VisionSensor>(elements[0]);
201 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 206 }
else if(type ==
"LIGHT_SWITCH"){
209 std::cerr <<
"can't find a light(" << elements[0] <<
")" 215 std::cerr <<
"unknown InPort data type(" << type <<
")" << std::endl;
222 std::vector<std::string> elements;
224 if (type ==
"JOINT_VALUE"){
225 std::vector<hrp::Link *>
joints;
230 }
else if(type ==
"JOINT_VELOCITY"){
231 std::vector<hrp::Link *>
joints;
236 }
else if(type ==
"JOINT_ACCELERATION"){
237 std::vector<hrp::Link *>
joints;
242 }
else if(type ==
"JOINT_TORQUE"){
243 std::vector<hrp::Link *>
joints;
248 }
else if(type ==
"ABS_TRANSFORM"){
249 if (elements.size()!=1){
250 std::cerr <<
"link name is not specified for port " << name
261 s = this->sensor<AccelSensor>(elements[0]);
262 if (!s) s = this->sensor<RateGyroSensor>(elements[0]);
263 if (!s) s = this->sensor<ForceSensor>(elements[0]);
264 if (!s) s = this->sensor<RangeSensor>(elements[0]);
265 if (!s) s = this->sensor<VisionSensor>(elements[0]);
271 std::cerr <<
"can't find a link(or a sensor)(" << elements[0] <<
")" 273 }
else if(type ==
"ABS_VELOCITY"){
274 if (elements.size()!=1){
275 std::cerr <<
"link name is not specified for port " << name
284 std::cerr <<
"can't find a link(" << elements[0] <<
")" 287 }
else if(type ==
"ABS_ACCELERATION"){
288 if (elements.size()!=1){
289 std::cerr <<
"link name is not specified for port " << name
298 std::cerr <<
"can't find a link(" << elements[0] <<
")" 301 }
else if(type ==
"FORCE_SENSOR"){
302 if (elements.size()!=1){
303 std::cerr <<
"sensor name is not specified for port" << name
307 ForceSensor *s = this->sensor<ForceSensor>(elements[0]);
309 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 315 }
else if(type ==
"RATE_GYRO_SENSOR"){
316 if (elements.size()!=1){
317 std::cerr <<
"sensor name is not specified for port " << name
323 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 329 }
else if(type ==
"ACCELERATION_SENSOR"){
330 if (elements.size()!=1){
331 std::cerr <<
"sensor name is not specified for port " << name
335 AccelSensor *s = this->sensor<AccelSensor>(elements[0]);
337 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 343 }
else if(type ==
"RANGE_SENSOR"){
344 if (elements.size()!=1){
345 std::cerr <<
"sensor name is not specified for port " << name
349 RangeSensor *s = this->sensor<RangeSensor>(elements[0]);
351 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 357 }
else if(type ==
"VISION_SENSOR"){
358 if (elements.size()!=1){
359 std::cerr <<
"sensor name is not specified for port " << name
363 VisionSensor *s = this->sensor<VisionSensor>(elements[0]);
365 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 370 }
else if(type ==
"POINT_CLOUD"){
371 if (elements.size()!=1){
372 std::cerr <<
"sensor name is not specified for port " << name
376 VisionSensor *s = this->sensor<VisionSensor>(elements[0]);
378 std::cerr <<
"can't find a sensor(" << elements[0] <<
")" 383 }
else if(type ==
"CONSTRAINT_FORCE"){
384 std::cout <<
"CONSTRAINT_FORCE is not implemented yet" << std::endl;
386 std::cerr <<
"unknown OutPort data type(" << type <<
")" << std::endl;
398 std::vector<int> &o_ids)
401 for (
unsigned int i=0;
i<i_names.size();
i++){
404 std::cout <<
"joint named [" << i_names[
i] <<
"] not found" 421 rs->force.length(
forces.size());
422 for(
size_t j = 0;
j <
forces.size();
j++) {
423 rs->force[
j].length(6);
424 for(
size_t i = 0;
i < 6;
i++ ) rs->force[
j][
i] =
forces[
j][
i];
426 rs->rateGyro.length(
gyros.size());
427 for(
size_t j = 0;
j <
gyros.size() ;
j++) {
428 rs->rateGyro[
j].length(3);
429 for(
size_t i = 0;
i < 3;
i++ ) rs->rateGyro[
j][
i] =
gyros[
j][
i];
431 rs->accel.length(
accels.size());
432 for(
size_t j = 0;
j <
accels.size();
j++) {
433 rs->accel[
j].length(3);
434 for(
size_t i = 0;
i < 3;
i++ ) rs->accel[
j][
i] =
accels[
j][
i];
439 for(
unsigned int i=0;
i < rs->servoState.length(); ++
i){
441 rs->servoState[
i].length(1);
444 status |= v<< OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT;
446 status |= v<< OpenHRP::RobotHardwareService::POWER_STATE_SHIFT;
448 status |= v<< OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT;
453 rs->servoState[
i][0] = status;
465 if (strcmp(i_jname,
"all") == 0 || strcmp(i_jname,
"ALL") == 0){
469 }
else if ((l =
link(i_jname))){
472 char *s = (
char *)i_jname;
while(*s) {*s=toupper(*s);s++;}
474 if (jgroup.size()==0)
return false;
475 for (
unsigned int i=0;
i<jgroup.size();
i++){
486 struct tm *tm_ = localtime(&tv.tv_sec);
487 static char time[20];
488 sprintf(time,
"%02d:%02d:%02d.%06d", tm_->tm_hour, tm_->tm_min, tm_->tm_sec, (
int)tv.tv_usec);
508 <<
": servo error limit over: joint = " 510 <<
", qRef = " << command/
M_PI*180 <<
"[deg], q = " 511 << angle/
M_PI*180 <<
"[deg]" << std::endl;
526 bool all_servo_off =
true;
527 bool emulate_highgain_servo_off_mode = (
numJoints() > 0);
533 if ( p && s ) { all_servo_off =
false;
continue; }
535 case Link::ROTATIONAL_JOINT:
540 }
else if ( j->
q > j->
ulimit ) {
547 std::cerr <<
"calcCMJacobian() : unsupported jointType(" 557 if (emulate_highgain_servo_off_mode) {
558 if ( all_servo_off ) {
577 accels[
i][1] = s->
dv[1];
578 accels[
i][2] = s->
dv[2];
583 gyros[
i][1] = s->
w[1];
584 gyros[
i][2] = s->
w[2];
589 forces[
i][1] = s->
f[1];
590 forces[
i][2] = s->
f[2];
591 forces[
i][3] = s->
tau[0];
592 forces[
i][4] = s->
tau[1];
593 forces[
i][5] = s->
tau[2];
603 #define JID_INVALID -2 608 if (strcmp(jname,
"all") == 0 || strcmp(jname,
"ALL") == 0){
611 ret = ret &&
servo(
i, turnon);
614 }
else if ((l =
link(jname))){
617 char *s = (
char *)jname;
while(*s) {*s=toupper(*s);s++;}
619 if (jgroup.size() == 0)
return false;
621 for (
unsigned int i=0;
i<jgroup.size();
i++){
622 ret = ret &&
servo(jgroup[
i], turnon);
633 if (strcmp(jname,
"all") == 0 || strcmp(jname,
"ALL") == 0){
637 if (!l)
return false;
640 return power(jid, turnon);
649 rs =
new OpenHRP::RobotHardwareService::RobotState();
654 rs =
new OpenHRP::RobotHardwareService::RobotState2();
659 return m_robot->power(jname, turnon == OpenHRP::RobotHardwareService::SWITCH_ON);
663 return m_robot->servo(jname, turnon == OpenHRP::RobotHardwareService::SWITCH_ON);
670 m_robot->setServoErrorLimit(jname, limit);
681 char *s = (
char *)gname;
while(*s) {*s=toupper(*s);s++;}
682 std::vector<int> jids;
683 std::vector<std::string>
joints;
684 joints.resize(jnames.length());
685 for (
unsigned int i=0;
i<jnames.length();
i++){
686 joints[
i] = jnames[
i];
690 m_robot->addJointGroup(gname, jids);
726 template <
class _Delete>
736 RTC::Create<BodyRTC>,
std::vector< OpenHRP::RobotHardwareService::SwitchStatus > servo_status
hrp::Vector3 m_lastServoOn_p
void createInPort(const std::string &config)
png_infop png_charpp int png_charpp profile
void setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm)
std::vector< hrp::dvector6 > forces
BodyRTC::emg_reason m_emergencyReason
void setServoErrorLimit(const char *jname, double limit)
void setServoTorqueGainPercentage(const char *jname, double limit)
std::vector< OpenHRP::RobotHardwareService::SwitchStatus > calib_status
void setDisturbanceObserverGain(::CORBA::Double gain)
png_infop png_charp png_int_32 png_int_32 int * type
CORBA::Long lengthDigitalInput()
RobotHardwareServicePort m_service0
void setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence &mns)
hrp::Matrix33 m_lastServoOn_R
RTC::ReturnCode_t setup()
bool power(int jid, bool turnon)
BodyRTC(RTC::Manager *manager=&RTC::Manager::instance())
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
std::vector< InPortHandlerBase * > m_inports
RTC::CorbaPort m_RobotHardwareServicePort
std::vector< hrp::Vector3 > gyros
void getDefaultRootPosition(Vector3 &out_p, Matrix33 &out_R)
int readPowerState(const int i)
CORBA::Boolean readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din)
void setAttitude(const Matrix33 &R)
std::vector< double > commands
bool names2ids(const std::vector< std::string > &i_names, std::vector< int > &o_ids)
void getStatus2(OpenHRP::RobotHardwareService::RobotState2 *rs)
unsigned int numSensors(int sensorType) const
void setRobot(BodyRTC *i_robot)
void setServoGainPercentage(const char *jname, double limit)
int readServoState(const int i)
std::map< std::string, std::vector< int > > m_jointGroups
static void moduleInit(RTC::Manager *)
void removeForceSensorOffset()
CORBA::Boolean addJointGroup(const char *gname, const OpenHRP::RobotHardwareService::StrSequence &jnames)
bool checkEmergency(emg_reason &o_reason, int &o_id)
CORBA::Long lengthDigitalOutput()
void calibrateInertiaSensor()
int gettimeofday(struct timeval *tv, struct timezone *tz)
RobotHardwareServicePort()
static const char * bodyrtc_spec[]
void parsePortConfig(const std::string &config, std::string &name, std::string &type, std::vector< std::string > &elements)
CORBA::Boolean writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence &dout)
CORBA::Boolean readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout)
bool servo(const char *jname, bool turnon)
def j(str, encoding="cp932")
const std::string & name()
void writeDataPorts(double time)
bool setServoErrorLimit(const char *i_jname, double i_limit)
void enableDisturbanceObserver()
CORBA::Boolean writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence &dout, const ::OpenHRP::RobotHardwareService::OctSequence &mask)
Link * joint(int id) const
~RobotHardwareServicePort()
void DummyDelete(RTC::RTObject_impl *rtc)
Light * light(const std::string &name)
Link * link(int index) const
#define DEFAULT_ANGLE_ERROR_LIMIT
Vector3 cross(const Vector3 &v1, const Vector3 &v2)
std::vector< OutPortHandlerBase * > m_outports
void getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs)
CORBA::Boolean servo(const char *jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
std::string sprintf(char const *__restrict fmt,...)
CORBA::Boolean power(const char *jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
unsigned int numJoints() const
const std::vector< Link * > & joints() const
bool addPort(PortBase &port)
std::vector< double > m_servoErrorLimit
void initializeJointAngle(const char *name, const char *option)
void disableDisturbanceObserver()
std::vector< hrp::Vector3 > accels
static std::vector< double > command
void getStatus(OpenHRP::RobotHardwareService::RobotState_out rs)
bool getJointList(hrp::Body *body, const std::vector< std::string > &elements, std::vector< hrp::Link * > &joints)
std::vector< double > angles
std::vector< OpenHRP::RobotHardwareService::SwitchStatus > power_status
CORBA::Boolean setJointInertia(const char *name,::CORBA::Double mn)
void getStatus(OpenHRP::RobotHardwareService::RobotState *rs)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
int readCalibState(const int i)
void createOutPort(const std::string &config)