10 #include "hrpsys/util/Hrpsys.h" 11 #include "hrpsys/idl/pointcloud.hh" 12 #include "hrpsys/idl/RobotHardwareService.hh" 22 "implementation_id",
"DataLogger",
23 "type_name",
"DataLogger",
24 "description",
"data logger component",
25 "version", HRPSYS_PACKAGE_VERSION,
27 "category",
"example",
28 "activity_type",
"DataFlowComponent",
31 "lang_type",
"compile",
33 "conf.default.log_precision",
"0",
38 #define LOG_SET_PRECISION(strm) \ 40 if (precision != 0) { \ 41 prc = os.precision(); \ 42 os << std::scientific << std::setprecision(precision); \ 45 #define LOG_UNSET_PRECISION(strm) \ 47 os << std::fixed << std::setprecision(prc); \ 49 void printData(std::ostream& os,
const RTC::Acceleration3D& data,
unsigned int precision = 0)
52 os << data.ax <<
" " << data.ay <<
" " << data.az <<
" ";
56 void printData(std::ostream& os,
const RTC::Velocity2D& data,
unsigned int precision = 0)
59 os << data.vx <<
" " << data.vy <<
" " << data.va <<
" ";
63 void printData(std::ostream& os,
const RTC::Pose3D& data,
unsigned int precision = 0)
66 os << data.position.x <<
" " << data.position.y <<
" " 67 << data.position.z <<
" " << data.orientation.r <<
" " 68 << data.orientation.p <<
" " << data.orientation.y <<
" ";
72 void printData(std::ostream& os,
const RTC::AngularVelocity3D& data,
unsigned int precision = 0)
75 os << data.avx <<
" " << data.avy <<
" " << data.avz <<
" ";
79 void printData(std::ostream& os,
const RTC::Point3D& data,
unsigned int precision = 0)
82 os << data.x <<
" " << data.y <<
" " << data.z <<
" ";
86 void printData(std::ostream& os,
const RTC::Vector3D& data,
unsigned int precision = 0)
89 os << data.x <<
" " << data.y <<
" " << data.z <<
" ";
93 void printData(std::ostream& os,
const RTC::Orientation3D& data,
unsigned int precision = 0)
96 os << data.r <<
" " << data.p <<
" " << data.y <<
" ";
100 void printData(std::ostream& os,
const PointCloudTypes::PointCloud& data,
unsigned int precision = 0)
102 uint npoint = data.data.length()/data.point_step;
103 os << data.width <<
" " << data.height <<
" " << data.type <<
" " << npoint;
104 float *
ptr = (
float *)data.data.get_buffer();
105 std::string
type(data.type);
106 if (type !=
"xyz" && type !=
"xyzrgb"){
107 std::cerr <<
"point cloud type(" << type <<
") is not supported" 112 os <<
" " << *ptr++ <<
" " << *ptr++ <<
" " << *ptr++;
113 if (type ==
"xyzrgb"){
114 unsigned char *rgb = (
unsigned char *)ptr;
115 os <<
" " << (
int)rgb[0] <<
" " << (
int)rgb[1] <<
" " << (
int)rgb[2];
122 std::ostream& operator<<(std::ostream& os, const _CORBA_Unbounded_Sequence<T > &
data)
124 for (
unsigned int j=0;
j<
data.length();
j++){
125 os <<
data[
j] <<
" ";
130 std::ostream&
operator<<(std::ostream& os,
const OpenHRP::RobotHardwareService::DblSequence6 & data)
132 for (
unsigned int j=0;
j<data.length();
j++){
133 os << data[
j] <<
" ";
138 std::ostream&
operator<<(std::ostream& os,
const OpenHRP::RobotHardwareService::DblSequence3 & data)
140 for (
unsigned int j=0;
j<data.length();
j++){
141 os << data[
j] <<
" ";
146 std::ostream&
operator<<(std::ostream& os,
const OpenHRP::RobotHardwareService::BatteryState & data)
148 os << data.voltage <<
" " << data.current <<
" " << data.soc <<
" ";
153 void printData(std::ostream& os,
const T& data,
unsigned int precision = 0)
156 for (
unsigned int j=0;
j<data.length();
j++){
157 os << data[
j] <<
" ";
162 void printData(std::ostream& os,
double data,
unsigned int precision = 0)
169 void printData(std::ostream& os,
const OpenHRP::RobotHardwareService::RobotState2& data,
unsigned int precision = 0)
174 printData(os, data.servoState, precision);
178 printData(os, data.batteries, precision);
181 printData(os, data.temperature, precision);
192 virtual void dumpLog(std::ostream& os,
unsigned int precision = 0){
193 os.setf(std::ios::fixed, std::ios::floatfield);
194 for (
unsigned int i=0;
i<
m_log.size();
i++){
198 void printLog(std::ostream& os, T &data,
unsigned int precision = 0){
199 os << std::setprecision(6) << (data.tm.sec + data.tm.nsec/1e9) <<
" ";
229 void dumpLog(std::ostream& os,
unsigned int precision = 0){
230 os.setf(std::ios::fixed, std::ios::floatfield);
231 for (
unsigned int i=0;
i<
m_log.size();
i++){
233 os << std::setprecision(6) << (
m_log[
i].tm.sec +
m_log[
i].tm.nsec/1e9) <<
" ";
244 m_emergencySignalIn(
"emergencySignal", m_emergencySignal),
245 m_DataLoggerServicePort(
"DataLoggerService"),
247 m_suspendFlag(false),
262 std::cerr <<
"[" <<
m_profile.instance_name <<
"] onInitialize()" << std::endl;
327 time_t sec = time(NULL);
328 struct tm *tm_ = localtime(&sec);
330 strftime(date,20,
"%Y-%m-%d", tm_);
332 sprintf(basename,
"emglog-%s-%02d%02d",
333 date, tm_->tm_hour, tm_->tm_min);
334 std::cout <<
"received emergency signal. saving log files(" 335 << basename <<
")" << std::endl;
346 for (
unsigned int i=0;
i<
m_ports.size();
i++){
391 for (
unsigned int i=0;
i<
m_ports.size();
i++){
393 std::cerr <<
"Logger port named \"" << i_name <<
"\" already exists" 401 if (strcmp(i_type,
"TimedDoubleSeq")==0){
408 }
else if (strcmp(i_type,
"TimedLongSeq")==0){
415 }
else if (strcmp(i_type,
"TimedBooleanSeq")==0){
422 }
else if (strcmp(i_type,
"TimedLongSeqSeq")==0){
429 }
else if (strcmp(i_type,
"TimedPoint3D")==0){
436 }
else if (strcmp(i_type,
"TimedVector3D")==0){
443 }
else if (strcmp(i_type,
"TimedOrientation3D")==0){
450 }
else if (strcmp(i_type,
"TimedAcceleration3D")==0){
457 }
else if (strcmp(i_type,
"TimedAngularVelocity3D")==0){
464 }
else if (strcmp(i_type,
"TimedVelocity2D")==0){
471 }
else if (strcmp(i_type,
"TimedPose3D")==0){
478 }
else if (strcmp(i_type,
"PointCloud")==0){
485 }
else if (strcmp(i_type,
"TimedRobotState2")==0){
493 std::cout <<
"DataLogger: unsupported data type(" << i_type <<
")" 507 for (
unsigned int i=0;
i<
m_ports.size();
i++){
508 std::string fname = i_basename;
511 std::ofstream ofs(fname.c_str());
515 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to open(" << fname <<
")" << std::endl;
519 if (ret) std::cerr <<
"[" <<
m_profile.instance_name <<
"] Save log to " << i_basename <<
".*" << std::endl;
527 for (
unsigned int i=0;
i<
m_ports.size();
i++){
530 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Log cleared" << std::endl;
550 for (
unsigned int i=0;
i<
m_ports.size();
i++){
553 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Log max length is set to " << len << std::endl;
564 RTC::Create<DataLogger>,
565 RTC::Delete<DataLogger>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
void setLogger(DataLogger *i_logger)
png_infop png_charp png_int_32 png_int_32 int * type
#define LOG_SET_PRECISION(strm)
std::ostream & operator<<(std::ostream &os, const _CORBA_Unbounded_Sequence< T > &data)
RTC::CorbaPort m_DataLoggerServicePort
png_infop png_charpp name
void printLog(std::ostream &os, T &data, unsigned int precision=0)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
virtual RTC::ReturnCode_t onInitialize()
std::string basename(const std::string name)
virtual const char * name()
void DataLoggerInit(RTC::Manager *manager)
DataLogger(RTC::Manager *manager)
Constructor.
LoggerPortForPointCloud(const char *name)
void maxLength(unsigned int len)
bool add(const char *i_type, const char *i_name)
ExecutionContextHandle_t UniqueId
coil::Mutex m_suspendFlagMutex
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
unsigned int m_log_precision
def j(str, encoding="cp932")
DataLoggerService_impl m_service0
InPort< TimedLong > m_emergencySignalIn
coil::Guard< coil::Mutex > Guard
static const char * nullcomponent_spec[]
#define LOG_UNSET_PRECISION(strm)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
virtual void dumpLog(std::ostream &os, unsigned int precision=0)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
std::vector< LoggerPortBase * > m_ports
std::string sprintf(char const *__restrict fmt,...)
LoggerPort(const char *name)
bool addPort(PortBase &port)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
bool save(const char *i_basename)
bool addInPort(const char *name, InPortBase &inport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void printData(std::ostream &os, const RTC::Acceleration3D &data, unsigned int precision=0)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
virtual ~DataLogger()
Destructor.
void dumpLog(std::ostream &os, unsigned int precision=0)