38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 50 #include <sys/types.h> 64 void usage(
const char *programNameP)
67 "USAGE: %s -f <calibration_file> [<options>]\n",
69 fprintf(stderr,
"Where <options> are:\n");
70 fprintf(stderr,
"\t-a <ip_address> : ip address (default=10.66.171.21)\n");
71 fprintf(stderr,
"\t-s : set the calibration (default is query)\n");
72 fprintf(stderr,
"\t-y : disable confirmation prompts\n");
77 bool fileExists(
const std::string& name)
80 return (0 == stat(name.c_str(), &sbuf));
83 const char *laserToSpindleNameP =
"laser_T_spindle";
84 const char *cameraToSpindleFixedNameP =
"camera_T_spindle_fixed";
87 std::ostream& writeLaserCal (std::ostream& stream,
lidar::Calibration const& calibration)
89 stream <<
"%YAML:1.0\n";
101 std::string ipAddress =
"10.66.171.21";
111 while(-1 != (c =
getopt(argc, argvPP,
"a:f:sy")))
113 case 'a': ipAddress = std::string(
optarg);
break;
114 case 'f': calFile = std::string(
optarg);
break;
115 case 's': setCal =
true;
break;
116 case 'y': prompt =
false;
break;
117 default:
usage(*argvPP);
break;
123 if (calFile.empty()) {
124 fprintf(stderr,
"Must provide a file argument\n");
128 if (
true == setCal &&
false == fileExists(calFile)) {
130 fprintf(stderr,
"file not found: \"%s\"\n", calFile.c_str());
134 if (
false == setCal &&
true == prompt &&
135 true == fileExists(calFile)) {
138 "\"%s\" already exists.\n\n" 139 "Really overwrite this file? (y/n): ",
144 if (
'Y' != c &&
'y' != c) {
145 fprintf(stdout,
"Aborting\n");
154 if (NULL == channelP) {
155 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
168 fprintf(stderr,
"failed to query sensor version: %s\n",
176 if (
false == setCal) {
182 fprintf(stderr,
"failed to query lidar calibration: %s\n",
187 std::ofstream cvFile (calFile.c_str (), std::ios_base::out | std::ios_base::trunc);
190 fprintf(stderr,
"failed to open '%s' for writing\n",
195 writeLaserCal (cvFile, c);
201 std::map<std::string, std::vector<float> > data;
202 std::ifstream cvFile (calFile.c_str ());
205 fprintf(stderr,
"failed to open '%s' for reading\n",
214 if (data[laserToSpindleNameP].size () != 4 * 4 ||
215 data[cameraToSpindleFixedNameP].size () != 4 * 4) {
217 fprintf(stderr,
"calibration matrices incomplete in %s, " 218 "expecting two 4x4 matrices\n", calFile.c_str());
224 memcpy (&c.
laserToSpindle[0][0], &data[laserToSpindleNameP].front (), data[laserToSpindleNameP].size () *
sizeof (float));
225 memcpy (&c.
cameraToSpindleFixed[0][0], &data[cameraToSpindleFixedNameP].front (), data[cameraToSpindleFixedNameP].size () *
sizeof (float));
229 fprintf(stderr,
"failed to set lidar calibration: %s\n",
234 fprintf(stdout,
"Lidar calibration successfully updated\n");
static const char * statusString(Status status)
int main(int argc, char **argvPP)
static Channel * Create(const std::string &sensorAddress)
float cameraToSpindleFixed[4][4]
std::ostream & writeMatrix(std::ostream &stream, std::string const &name, uint32_t rows, uint32_t columns, T const *data)
virtual Status getLidarCalibration(lidar::Calibration &c)=0
int getopt(int argc, char **argv, char *opts)
static CRL_CONSTEXPR Status Status_Ok
float laserToSpindle[4][4]
virtual Status setLidarCalibration(const lidar::Calibration &c)=0
std::istream & parseYaml(std::istream &stream, std::map< std::string, std::vector< float > > &data)
static void Destroy(Channel *instanceP)
virtual Status getSensorVersion(VersionType &version)=0