12 #include <hrpModel/ModelLoaderUtil.h> 14 #include "hrpsys/util/VectorConvert.h" 24 "implementation_id",
"ServoController",
25 "type_name",
"ServoController",
26 "description",
"null component",
27 "version", HRPSYS_PACKAGE_VERSION,
29 "category",
"example",
30 "activity_type",
"DataFlowComponent",
33 "lang_type",
"compile",
42 m_ServoControllerServicePort(
"ServoControllerService")
56 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
81 std::string devname = prop[
"servo.devname"];
82 if ( devname ==
"" ) {
83 std::cerr <<
"\e[1;31m[WARNING] " <<
m_profile.instance_name <<
": needs servo.devname property\e[0m" << std::endl;
84 std::cerr <<
"\e[1;31m[WARNING] " <<
m_profile.instance_name <<
": running in dummy mode\e[0m" << std::endl;
90 if ( servo_ids.size() == 0 ) {
91 std::cerr <<
"\e[1;31m[ERROR] " <<
m_profile.instance_name <<
": needs servo.id property\e[0m" << std::endl;
92 return RTC::RTC_ERROR;
95 for(
unsigned int i = 0;
i < servo_ids.size();
i++) {
99 std::cout <<
m_profile.instance_name <<
": servo_id : ";
100 for(
unsigned int i = 0;
i <
servo_id.size();
i++) {
103 std::cerr << std::endl;
107 if ( servo_offsets.size() == 0 ) {
113 std::cerr <<
"\e[1;31m[ERROR] " <<
m_profile.instance_name <<
": servo.id and servo.offset property must have same length\e[0m" << std::endl;
114 return RTC::RTC_ERROR;
116 for(
unsigned int i = 0;
i < servo_offsets.size();
i++) {
120 std::cout <<
m_profile.instance_name <<
": servo_offset : ";
124 std::cerr << std::endl;
128 if ( servo_dirs.size() == 0 ) {
133 if ( servo_ids.size() !=
servo_dir.size() ) {
134 std::cerr <<
"\e[1;31m[ERROR] " <<
m_profile.instance_name <<
": servo.id and servo.dir property must have same length\e[0m" << std::endl;
135 return RTC::RTC_ERROR;
137 for(
unsigned int i = 0;
i < servo_dirs.size();
i++) {
141 std::cout <<
m_profile.instance_name <<
": servo_dir : ";
145 std::cerr << std::endl;
176 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
177 if ( !
serial )
return RTC::RTC_OK;
184 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
185 if ( !
serial )
return RTC::RTC_OK;
232 if ( !
serial )
return true;
233 double rad = angle *
M_PI / 180;
242 if ( !
serial )
return true;
247 for(
unsigned int i = 0;
i <
servo_id.size();
i++ ) {
252 if ( angles.length() !=
servo_id.size() ) {
253 std::cerr <<
"[ERROR] " <<
m_profile.instance_name <<
": size of servo.id(" << angles.length() <<
") is not correct, expected" <<
servo_id.size() << std::endl;
262 if ( !
serial )
return true;
268 angle -= servo_offset_angle;
272 if (ret < 0)
return false;
278 if ( !
serial )
return true;
282 angles =
new OpenHRP::ServoControllerService::dSequence();
286 if (ret < 0)
return false;
293 if ( !
serial )
return true;
295 std::vector<int> indices;
296 for (
size_t i=0;
i<ids.length();
i++){
297 indices.push_back(ids[
i]);
306 if ( !
serial )
return true;
313 if ( !
serial )
return true;
317 if ( angles.length() != len ) {
318 std::cerr <<
"[ERROR] " <<
m_profile.instance_name <<
": size of servo.id(" << angles.length() <<
") is not correct, expected" << len << std::endl;
324 for(
unsigned int i = 0;
i < len;
i++ ) {
328 for(
unsigned int j = 0;
j <
servo_id.size();
j++ ) {
334 rad[
i] = (angles.get_buffer()[
i])*dir+offset;
343 if ( !
serial )
return true;
347 if (ret < 0)
return false;
353 if ( !
serial )
return true;
357 if (ret < 0)
return false;
363 if ( !
serial )
return true;
367 if (ret < 0)
return false;
373 if ( !
serial )
return true;
377 if (ret < 0)
return false;
383 if ( !
serial )
return true;
387 if (ret < 0)
return false;
393 if ( !
serial )
return true;
397 if (ret < 0)
return false;
403 if ( !
serial )
return true;
407 if (ret < 0)
return false;
413 if ( !
serial )
return true;
417 if (ret < 0)
return false;
423 if ( !
serial )
return true;
427 for (vector<int>::iterator it =
servo_id.begin(); it !=
servo_id.end(); it++ ){
429 if (ret < 0)
return false;
437 if ( !
serial )
return true;
441 for (vector<int>::iterator it =
servo_id.begin(); it !=
servo_id.end(); it++ ){
443 if (ret < 0)
return false;
456 RTC::Create<ServoController>,
457 RTC::Delete<ServoController>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
bool setJointAngles(const OpenHRP::ServoControllerService::dSequence angles, double tm)
void ServoControllerInit(RTC::Manager *manager)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
static const char * nullcomponent_spec[]
std::vector< int > servo_id
bool stringTo(To &val, const char *str)
bool getVoltage(short id, double &voltage)
bool removeJointGroup(const char *gname)
int getSpeed(int id, double *duration)
bool setMaxTorque(short id, short percentage)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
int getVoltage(int id, double *voltage)
int getPosition(int id, double *angle)
int getDuration(int id, double *duration)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onInitialize()
bool getJointAngle(short id, double &angle)
bool getJointAngles(OpenHRP::ServoControllerService::dSequence_out &angles)
std::vector< double > servo_dir
std::vector< double > servo_offset
virtual RTC::ReturnCode_t onFinalize()
coil::Properties & getProperties()
bool setJointAnglesOfGroup(const char *gname, const ::OpenHRP::ServoControllerService::dSequence angles, double tm)
virtual ~ServoController()
Destructor.
bool addJointGroup(const char *gname, const ::OpenHRP::ServoControllerService::iSequence ids)
ServoControllerService_impl m_service0
int getTemperature(int id, double *temperature)
bool getTemperature(short id, double &temperature)
bool getTorque(short id, double &torque)
std::vector< std::string > vstring
std::map< std::string, std::vector< int > > joint_groups
RTC::CorbaPort m_ServoControllerServicePort
int setMaxTorque(int id, short percentage)
ExecutionContextHandle_t UniqueId
int getTorque(int id, double *torque)
def j(str, encoding="cp932")
bool getSpeed(short id, double &speed)
int getMaxTorque(int id, short *percentage)
bool setJointAngle(short id, double angle, double tm)
int setPosition(int id, double rad)
int setPositions(int len, int *id, double *rad)
bool getMaxTorque(short id, short &percentage)
bool addPort(PortBase &port)
bool getDuration(short id, double &duration)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void servo(ServoController *i_servo)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
ServoController(RTC::Manager *manager)
Constructor.
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)