iCub-main
Loading...
Searching...
No Matches
stereoCalibModule.cpp
Go to the documentation of this file.
1#include "stereoCalibModule.h"
2#include <yarp/os/Stamp.h>
3#include <yarp/os/Os.h>
4
5
6
7bool stereoCalibModule::configure(yarp::os::ResourceFinder &rf)
8{
9 moduleName=rf.check("name",Value("stereoCalib"),"module name (string)").asString().c_str();
10 setName(moduleName.c_str());
11
12 handlerPortName="/";
13 handlerPortName+=getName(rf.check("CommandPort",Value("/cmd"),"Output image port (string)").asString());
14
15 char dirName[255];
16 bool proceed=true;
17 string dir=rf.getHomeContextPath().c_str();
18
19 for (int i=1; proceed; i++)
20 {
21 sprintf(dirName,"%s/%s_%.5d",dir.c_str(),"calibImg",i);
22 proceed=!yarp::os::stat(dirName);
23 sprintf(dirName,"%s/%s_%.5d/",dir.c_str(),"calibImg",i);
24 }
25 yarp::os::mkdir_p(dirName);
26
27 if (!handlerPort.open(handlerPortName.c_str()))
28 {
29 cout << ": unable to open port " << handlerPortName << endl;
30 return false;
31 }
32 attach(handlerPort);
33
34 calibThread=new stereoCalibThread(rf,&handlerPort,dirName);
35 calibThread->start();
36
37 return true;
38}
39
40
42{
43 calibThread->stopCalib();
44 calibThread->stop();
45 return true;
46}
47
48
50{
51 calibThread->stop();
52 delete calibThread;
53
54 return true;
55}
56
57
58bool stereoCalibModule::respond(const Bottle& command, Bottle& reply)
59{
60 reply.clear();
61
62 if(command.size() == 0)
63 {
64 reply.addString("error");
65 reply.addString("empty command");
66 return true;
67 }
68
69 const std::string cmd = command.get(0).asString();
70
71 if (cmd == "start") {
72 calibThread->startCalib();
73 reply.addString("ok");
74 reply.addString("calibration collection started");
75 }
76 else if(cmd == "stop")
77 {
78 calibThread->stopCalib();
79 reply.addString("ok");
80 reply.addString("calibration collection stopped");
81 }
82 else if(cmd == "status")
83 {
84 StereoCalibStatus status = calibThread->getStatus();
85 reply.addString("ok");
86 reply.addString("state");
87 reply.addString(status.state);
88 reply.addString("pairedFrames");
89 reply.addInt64(status.pairedFrames);
90 reply.addString("droppedLeftFrames");
91 reply.addInt64(status.droppedLeftFrames);
92 reply.addString("droppedRightFrames");
93 reply.addInt64(status.droppedRightFrames);
94 reply.addString("meanTimestampDeltaMs");
95 reply.addFloat64(status.meanTimestampDeltaMs);
96 reply.addString("maxTimestampDeltaMs");
97 reply.addFloat64(status.maxTimestampDeltaMs);
98
99 // Do not report unavailable calibration values as zero. These fields
100 // appear only after the engine has completed successfully.
101 if(status.calibrationAvailable)
102 {
103 reply.addString("calibrationMode");
104 reply.addString(status.calibrationMode);
105 if(status.leftMonocularRms >= 0.0)
106 {
107 reply.addString("leftMonocularRms");
108 reply.addFloat64(status.leftMonocularRms);
109 }
110 if(status.rightMonocularRms >= 0.0)
111 {
112 reply.addString("rightMonocularRms");
113 reply.addFloat64(status.rightMonocularRms);
114 }
115 if(status.stereoRms >= 0.0)
116 {
117 reply.addString("stereoRms");
118 reply.addFloat64(status.stereoRms);
119 }
120 if(status.baselineNorm >= 0.0)
121 {
122 reply.addString("baselineNorm");
123 reply.addFloat64(status.baselineNorm);
124 }
125 if(status.medianVerticalRectificationErrorPx >= 0.0)
126 {
127 reply.addString("medianVerticalRectificationErrorPx");
128 reply.addFloat64(status.medianVerticalRectificationErrorPx);
129 }
130 if(status.p95VerticalRectificationErrorPx >= 0.0)
131 {
132 reply.addString("p95VerticalRectificationErrorPx");
133 reply.addFloat64(status.p95VerticalRectificationErrorPx);
134 }
135 if(status.maxVerticalRectificationErrorPx >= 0.0)
136 {
137 reply.addString("maxVerticalRectificationErrorPx");
138 reply.addFloat64(status.maxVerticalRectificationErrorPx);
139 }
140 }
141
142 reply.addString("lastCalibrationError");
143 reply.addString(status.lastCalibrationError.empty() ? "unavailable" : status.lastCalibrationError);
144 }
145 else if(cmd == "help")
146 {
147 reply.addString("available commands: start stop status help quit");
148 }
149 else if(cmd == "quit")
150 {
151 reply.addString("quitting");
152 return false;
153 }
154 else
155 {
156 reply.addString("error");
157 reply.addString("unknown command");
158 }
159
160 return true;
161}
162
163
165{
166 return true;
167}
168
169
171{
172 return 0.1;
173}
bool respond(const Bottle &command, Bottle &reply)
bool configure(yarp::os::ResourceFinder &rf)
StereoCalibStatus getStatus() const
cmd
Definition dataTypes.h:30
std::string lastCalibrationError
double maxVerticalRectificationErrorPx
std::size_t droppedLeftFrames
double p95VerticalRectificationErrorPx
std::string calibrationMode
double medianVerticalRectificationErrorPx
std::size_t droppedRightFrames