3 #include "hrpsys/util/OpenRTMUtil.h" 9 m_rhCompName(
"RobotHardware0"),
10 m_shCompName(
"StateHolder0"),
12 m_interval(i_interval)
16 sprintf(buf,
"%s:%d", i_hostname.c_str(), i_port);
18 m_naming = CosNaming::NamingContext::_duplicate(naming.getRootContext());
19 }
catch (CORBA::SystemException& ex) {
20 std::cerr <<
"[monitor] Failed to initialize CORBA " << std::endl << ex._rep_id() <<
" with " << buf << std::endl;
21 }
catch (
const std::string&
error){
22 std::cerr <<
"[monitor] Failed to initialize CORBA " << std::endl << error <<
" with " << buf << std::endl;
24 std::cerr <<
"[monitor] Failed to initialize CORBA with " << buf << std::endl;
30 static long long loop = 0;
39 name[0].kind = CORBA::string_dup(
"rtc");
41 RTC::RTObject_var rtc = RTC::RTObject::_narrow(obj);
42 RTC::ExecutionContextList_var eclist = rtc->get_owned_contexts();
43 for(CORBA::ULong
i=0;
i < eclist->length(); ++
i){
44 eclist[
i]->activate_component(rtc);
47 m_rhService = OpenHRP::RobotHardwareService::_narrow(
m_orb->string_to_object(ior));
50 std::cerr <<
"[monitor] RobotHardwareService could not connect (" <<
m_rhCompName <<
")" << std::endl;
54 std::cerr <<
"[monitor] RobotHardwareService is not found (" <<
m_rhCompName <<
")" << std::endl;
62 name[0].kind = CORBA::string_dup(
"rtc");
64 RTC::RTObject_var rtc = RTC::RTObject::_narrow(obj);
66 m_shService = OpenHRP::StateHolderService::_narrow(
m_orb->string_to_object(ior));
69 std::cerr <<
"[monitor] StateHolderService could not connect (" <<
m_shCompName <<
")" << std::endl;
73 std::cerr <<
"[monitor] StateHolderService is not found (" <<
m_shCompName <<
")" << std::endl;
76 bool stateUpdate =
false;
78 OpenHRP::RobotHardwareService::RobotState_var rs;
84 std::cerr <<
"[monitor] exception in getStatus()" << std::endl;
90 OpenHRP::StateHolderService::Command_var
com;
96 std::cerr <<
"[monitor] exception in getCommand()" << std::endl;
131 OpenHRP::RobotHardwareService::RobotState &rstate = lm->
state().
state;
133 fprintf(stdout,
"\e[1;1H");
134 fprintf(stdout,
"\x1b[42m");
136 fprintf(stdout,
"\e[2KTimestamp %16.4f, elapsed time %8.4f\n", lm->
state().
time, lm->
currentTime());
137 double curr_time, prev_time;
138 std::vector<double> curr_angle, prev_angle, velocity, curr_vel, prev_vel, curr_acc, acceleration;
139 int n = body->numJoints();
140 curr_angle.resize(n); prev_angle.resize(n); curr_vel.resize(n); prev_vel.resize(n); curr_acc.resize(n);
141 velocity.resize(n); acceleration.resize(n);
142 for(
int i = 0;
i < n;
i++) { prev_angle[
i] = lm->
state().
state.angle[
i]; velocity[
i] = acceleration[
i] = curr_vel[
i] = 0; }
146 for(
int i = 0;
i < n;
i++) {
148 curr_vel[
i] = (curr_angle[
i] - prev_angle[
i])/(curr_time-prev_time);
149 curr_acc[
i] = (curr_vel[
i] - prev_vel[
i])/(curr_time-prev_time);
150 if (fabs(velocity[
i]) < fabs(curr_vel[i])) velocity[i] = curr_vel[i];
151 if (fabs(acceleration[i]) < fabs(curr_acc[i])) acceleration[i] = curr_acc[i];
154 for(
int i = 0;
i < n;
i++) { prev_angle[
i] = curr_angle[
i]; prev_vel[
i] = curr_vel[
i];}
155 prev_time = curr_time;
158 fprintf(stdout,
"\e[2KID PW NAME ANGLE COMMAND ERROR VELOCITY ACCEL. TORQUE SERVO TEMP\n");
160 for (
unsigned int i=0;
i<body->numJoints();
i++){
163 fprintf(stdout,
"\e[2K");
164 int ss = rstate.servoState[
i][0];
171 fprintf(stdout,
"%2d ",
i);
175 fprintf(stdout,
" o ");
178 fprintf(stdout,
"%20s ", l->
name.c_str());
180 if(
i<rstate.angle.length() )
181 fprintf(stdout,
"%8.3f ", rstate.angle[
i]*180/
M_PI);
183 fprintf(stdout,
"-------- ");
185 if(
i<rstate.command.length() )
186 fprintf(stdout,
"%8.3f ", rstate.command[
i]*180/
M_PI);
188 fprintf(stdout,
"-------- ");
191 if(
i<rstate.angle.length() &&
i<rstate.command.length() ){
192 double e = (rstate.angle[
i]-rstate.command[
i])*180/
M_PI;
193 if ( std::abs(e) > 1 )
yellow();
194 if ( std::abs(e) > 2 )
magenta();
195 if ( std::abs(e) > 4 )
red();
196 fprintf(stdout,
"%8.3f ", e);
199 fprintf(stdout,
"-------- ");
202 if(
i<velocity.size() ) {
203 double e = velocity[
i];
204 if ( std::abs(e) > 2 )
yellow();
205 if ( std::abs(e) > 10 )
magenta();
206 if ( std::abs(e) > 20 )
red();
207 fprintf(stdout,
"%8.2f ", e);
210 fprintf(stdout,
"-------- ");
213 if(
i<acceleration.size() ) {
214 double e = acceleration[
i];
215 if ( std::abs(e) > 50 )
yellow();
216 if ( std::abs(e) > 100 )
magenta();
217 if ( std::abs(e) > 200 )
red();
218 fprintf(stdout,
"%8.1f ", e);
221 fprintf(stdout,
"-------- ");
225 if(
i<rstate.torque.length() )
226 fprintf(stdout,
"%6.1f ", rstate.torque[
i]*180/
M_PI);
228 fprintf(stdout,
"------ ");
234 fprintf(stdout,
"-- ");
236 if (temp >= 60)
red();
237 fprintf(stdout,
"%2d ", temp);
238 if (temp >= 60)
black();
240 fprintf(stdout,
"\n");
243 fprintf(stdout,
"\e[2K---\n");
245 if (rstate.accel.length()){
246 fprintf(stdout,
"\e[2K acc:");
247 for (
unsigned int i=0;
i<rstate.accel.length();
i++){
248 if(
i>0)fprintf(stdout,
"\e[2K ");
249 fprintf(stdout,
" %8.4f %8.4f %8.4f\n",
250 rstate.accel[
i][0], rstate.accel[
i][1], rstate.accel[
i][2]);
253 if (rstate.rateGyro.length()){
254 fprintf(stdout,
"\e[2K rate:");
255 for (
unsigned int i=0;
i<rstate.rateGyro.length();
i++){
256 if(
i>0)fprintf(stdout,
"\e[2K ");
257 fprintf(stdout,
" %8.4f %8.4f %8.4f\n",
258 rstate.rateGyro[
i][0], rstate.rateGyro[
i][1], rstate.rateGyro[
i][2]);
261 if (rstate.force.length()){
262 fprintf(stdout,
"\e[2Kforce/torque:");
263 for (
unsigned int i=0;
i<rstate.force.length();
i++){
264 if(
i>0)fprintf(stdout,
"\e[2K ");
265 fprintf(stdout,
" %6.1f %6.1f %6.1f %6.2f %6.2f %6.2f\n",
274 fprintf(stdout,
"\e[2K\n");
Monitor(CORBA::ORB_var orb, const std::string &i_hostname, int i_port, int i_interval, LogManager< TimedRobotState > *i_log)
OpenHRP::RobotHardwareService_var m_rhService
png_infop png_charpp name
void error(char *msg) const
const char * getServiceIOR(RTC::RTObject_var rtc, const char *sname)
OpenHRP::RobotHardwareService::RobotState state
void setStateHolderName(const char *i_name)
int gettimeofday(struct timeval *tv, struct timezone *tz)
void showStatus(hrp::BodyPtr &body)
OpenHRP::StateHolderService_var m_shService
CosNaming::NamingContext_var m_naming
LogManager< TimedRobotState > * m_log
OpenHRP::StateHolderService::Command command
std::string sprintf(char const *__restrict fmt,...)
void setRobotHardwareName(const char *i_name)
int usleep(useconds_t usec)