10 #include "hrpsys/util/VectorConvert.h" 12 #include <hrpModel/ModelLoaderUtil.h> 15 #include <hrpModel/Sensor.h> 16 #include "hrpsys/idl/RobotHardwareService.hh" 27 "implementation_id",
"EmergencyStopper",
28 "type_name",
"EmergencyStopper",
29 "description",
"emergency stopper",
30 "version", HRPSYS_PACKAGE_VERSION,
32 "category",
"example",
33 "activity_type",
"DataFlowComponent",
36 "lang_type",
"compile",
38 "conf.default.debugLevel",
"0",
43 static std::ostream&
operator<<(std::ostream& os,
const struct RTC::Time &tm)
45 int pre = os.precision();
46 os.setf(std::ios::fixed);
47 os << std::setprecision(6)
48 << (tm.sec + tm.nsec/1e9)
49 << std::setprecision(pre);
50 os.unsetf(std::ios::fixed);
57 m_qRefIn(
"qRef", m_qRef),
58 m_emergencySignalIn(
"emergencySignal", m_emergencySignal),
59 m_servoStateIn(
"servoStateIn", m_servoState),
61 m_emergencyModeOut(
"emergencyMode", m_emergencyMode),
62 m_beepCommandOut(
"beepCommand", m_beepCommand),
63 m_EmergencyStopperServicePort(
"EmergencyStopperService"),
68 emergency_stopper_beep_count(0),
79 #define DEBUGP ((m_debugLevel==1 && loop%200==0) || m_debugLevel > 1 ) 82 std::cerr <<
"[" <<
m_profile.instance_name <<
"] onInitialize()" << std::endl;
115 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
116 int comPos = nameServer.find(
",");
118 comPos = nameServer.length();
120 nameServer = nameServer.substr(0, comPos);
122 OpenHRP::BodyInfo_var binfo;
124 CosNaming::NamingContext::_duplicate(
naming.getRootContext()));
125 if (CORBA::is_nil(binfo)) {
126 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" 128 return RTC::RTC_ERROR;
131 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" << std::endl;
132 return RTC::RTC_ERROR;
136 OpenHRP::LinkInfoSequence_var lis = binfo->links();
137 std::vector<std::string> fsensor_names;
139 for (
unsigned int k = 0; k < lis->length(); k++ ) {
140 OpenHRP::SensorInfoSequence& sensors = lis[k].sensors;
141 for (
unsigned int l = 0;
l < sensors.length();
l++ ) {
142 if ( std::string(sensors[
l].
type) ==
"Force" ) {
143 fsensor_names.push_back(std::string(sensors[
l].
name));
147 unsigned int npforce = fsensor_names.
size();
150 unsigned int nvforce = virtual_force_sensor.size()/10;
151 for (
unsigned int i=0;
i<nvforce;
i++){
152 fsensor_names.push_back(virtual_force_sensor[
i*10+0]);
155 unsigned int nforce = npforce + nvforce;
160 for (
unsigned int i=0;
i<nforce;
i++){
170 registerOutPort(std::string(fsensor_names[i]+
"Out").c_str(), *m_wrenchesOut[i]);
191 for(
unsigned int i=0;
i<
m_robot->numJoints();
i++){
195 for(
unsigned int i=0;
i<nforce;
i++){
196 for(
int j=0; j<6; j++){
203 for(
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
206 status |= 1<< OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT;
207 status |= 1<< OpenHRP::RobotHardwareService::POWER_STATE_SHIFT;
208 status |= 1<< OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT;
209 status |= 0<< OpenHRP::RobotHardwareService::SERVO_ALARM_SHIFT;
210 status |= 0<< OpenHRP::RobotHardwareService::DRIVER_TEMP_SHIFT;
248 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onActivated(" << ec_id <<
")" << std::endl;
254 std::cerr <<
"[" <<
m_profile.instance_name<<
"] onDeactivated(" << ec_id <<
")" << std::endl;
267 unsigned int numJoints =
m_robot->numJoints();
285 assert(
m_qRef.data.length() == numJoints);
286 std::vector<double> current_posture;
287 for (
unsigned int i = 0;
i <
m_qRef.data.length();
i++ ) {
288 current_posture.push_back(
m_qRef.data[
i]);
295 for (
unsigned int i = 0;
i <
m_qRef.data.length();
i++ ) {
309 std::vector<double> current_wrench;
311 for (
int j = 0; j < 6; j++ ) {
321 for (
int j = 0; j < 6; j++ ) {
337 <<
"] emergencySignal is reset!" << std::endl;
342 <<
"] emergencySignal is set!" << std::endl;
372 for (
unsigned int i = 0;
i <
m_q.data.length();
i++ ) {
376 for (
int j = 0; j < 6; j++ ) {
398 for (
unsigned int i = 0;
i < numJoints;
i++) {
399 std::cerr <<
" " <<
m_q.data[
i] ;
401 std::cerr << std::endl;
402 std::cerr <<
"wrenches: ";
404 for (
int j = 0; j < 6; j++ ) {
408 std::cerr << std::endl;
427 bool has_servoOn =
false;
428 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++ ){
429 int servo_state = (
m_servoState.data[
i][0] & OpenHRP::RobotHardwareService::SERVO_STATE_MASK) >> OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT;
430 has_servoOn = has_servoOn || (servo_state == 1);
490 std::cerr <<
"[" <<
m_profile.instance_name <<
"] stopMotion is called" << std::endl;
500 std::cerr <<
"[" <<
m_profile.instance_name <<
"] releaseMotion is called" << std::endl;
507 std::cerr <<
"[" <<
m_profile.instance_name <<
"] getEmergencyStopperParam" << std::endl;
516 std::cerr <<
"[" <<
m_profile.instance_name <<
"] setEmergencyStopperParam" << std::endl;
530 RTC::Create<EmergencyStopper>,
531 RTC::Delete<EmergencyStopper>);
ComponentProfile m_profile
virtual RTC::ReturnCode_t onFinalize()
png_infop png_charpp int png_charpp profile
static const char * emergencystopper_spec[]
bool setEmergencyStopperParam(const OpenHRP::EmergencyStopperService::EmergencyStopperParam &i_param)
bool getEmergencyStopperParam(OpenHRP::EmergencyStopperService::EmergencyStopperParam &i_param)
png_infop png_charp png_int_32 png_int_32 int * type
interpolator * m_wrenches_interpolator
HRPMODEL_API OpenHRP::BodyInfo_var loadBodyInfo(const char *url, int &argc, char *argv[])
OutPort< TimedLong > m_emergencyModeOut
bool stringTo(To &val, const char *str)
OutPort< TimedLongSeq > m_beepCommandOut
png_infop png_charpp name
TimedLong m_emergencySignal
TimedLong m_emergencyMode
void setName(const std::string &_name)
void get_wrenches_array_from_data(const std::vector< TimedDoubleSeq > &wrenches_data, double *wrenches_array)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
coil::Guard< coil::Mutex > Guard
TimedLongSeq m_beepCommand
coil::Properties & getProperties()
virtual RTC::ReturnCode_t onInitialize()
static Manager & instance()
RTC::CorbaPort m_EmergencyStopperServicePort
bool addOutPort(const char *name, OutPortBase &outport)
void setDataPort(RTC::TimedLongSeq &out_data)
int get_num_beep_info() const
boost::shared_ptr< Body > BodyPtr
InPort< TimedDoubleSeq > m_qRefIn
EmergencyStopperService_impl m_service0
std::queue< std::vector< double > > m_input_posture_queue
std::vector< std::string > vstring
coil::Properties & getConfig()
void startBeep(const int _freq, const int _length=50)
int emergency_stopper_beep_freq
InPort< OpenHRP::TimedLongSeqSeq > m_servoStateIn
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
interpolator * m_interpolator
virtual ~EmergencyStopper()
Destructor.
std::vector< TimedDoubleSeq > m_wrenchesRef
OpenHRP::TimedLongSeqSeq m_servoState
std::queue< std::vector< double > > m_input_wrenches_queue
static std::ostream & operator<<(std::ostream &os, const struct RTC::Time &tm)
std::vector< OutPort< TimedDoubleSeq > * > m_wrenchesOut
unsigned int m_debugLevel
EmergencyStopper(RTC::Manager *manager)
Constructor.
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
void registerInPort(const char *name, InPortBase &inport)
void get(double *x_, bool popp=true)
bool addPort(PortBase &port)
virtual bool write(DataType &value)
int emergency_stopper_beep_count
void emergencystopper(EmergencyStopper *i_emergencystopper)
int loadBodyFromBodyInfo(::World *world, const char *_name, BodyInfo_ptr bodyInfo)
std::vector< InPort< TimedDoubleSeq > * > m_wrenchesIn
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
void EmergencyStopperInit(RTC::Manager *manager)
int default_retrieve_time
bool addInPort(const char *name, InPortBase &inport)
void setGoal(const double *gx, const double *gv, double time, bool online=true)
void registerOutPort(const char *name, OutPortBase &outport)
InPort< TimedLong > m_emergencySignalIn
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void set_wrenches_data_from_array(std::vector< TimedDoubleSeq > &wrenches_data, const double *wrenches_array)
void set(const double *x, const double *v=NULL)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
OutPort< TimedDoubleSeq > m_qOut
std::vector< TimedDoubleSeq > m_wrenches