39 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 44 #include <netinet/in.h> 46 #include <sys/select.h> 47 #include <sys/socket.h> 48 #include <visp3/core/vpDebug.h> 49 #include <visp3/core/vpMath.h> 50 #include <visp3/core/vpTime.h> 51 #include <visp3/sensor/vpSickLDMRS.h> 72 : socket_fd(-1), body(NULL), vAngle(), time_offset(0), isFirstMeasure(true), maxlen_body(104000)
74 ip =
"131.254.12.119";
107 return (this->
setup());
117 struct sockaddr_in serv_addr;
123 socket_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
125 fprintf(stderr,
"Failed to create socket\n");
129 memset(&serv_addr, 0,
sizeof(serv_addr));
130 serv_addr.sin_family = AF_INET;
131 serv_addr.sin_addr.s_addr = inet_addr(
ip.c_str());
132 serv_addr.sin_port = htons(
port);
135 res = connect(
socket_fd, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr));
136 if (errno == EINPROGRESS) {
140 FD_SET(static_cast<unsigned int>(
socket_fd), &myset);
141 res = select(
socket_fd + 1, NULL, &myset, NULL, &tv);
142 if (res < 0 && errno != EINTR) {
143 fprintf(stderr,
"Error connecting to server %d - %s\n", errno, strerror(errno));
145 }
else if (res > 0) {
146 fprintf(stderr,
"ok");
148 fprintf(stderr,
"Timeout in select() - Cancelling!\n");
164 unsigned int *uintptr;
165 unsigned short *ushortptr;
166 static unsigned char header[24];
167 ushortptr = (
unsigned short *)header;
168 uintptr = (
unsigned int *)header;
170 assert(
sizeof(header) == 24);
173 double time_second = 0;
180 if (recv(
socket_fd, header,
sizeof(header), MSG_WAITALL) == -1) {
187 printf(
"Error, wrong magic number !!!\n");
192 uint16_t msgtype = ntohs(ushortptr[7]);
193 uint32_t msgLength = ntohl(uintptr[2]);
196 if (len != (ssize_t)msgLength) {
197 printf(
"Error, wrong msg length: %d of %d bytes.\n", (
int)len, msgLength);
209 unsigned short measurementId;
210 ushortptr = (
unsigned short *)
body;
211 measurementId = ushortptr[0];
214 uintptr = (
unsigned int *)(
body + 6);
215 unsigned int seconds = uintptr[1];
216 unsigned int fractional = uintptr[0];
217 double startTimestamp = seconds + fractional / 4294967296.;
220 uintptr = (
unsigned int *)(
body + 14);
221 seconds = uintptr[1];
222 fractional = uintptr[0];
223 double endTimestamp = seconds + fractional / 4294967296.;
235 unsigned short numSteps = ushortptr[11];
238 short startAngle = (short)ushortptr[12];
239 short stopAngle = (short)ushortptr[13];
244 unsigned short numPoints = ushortptr[14];
247 for (
int i = 0; i < nlayers; i++) {
248 laserscan[i].
clear();
263 if (numPoints > USHRT_MAX - 2)
266 for (
int i = 0; i < numPoints; i++) {
267 ushortptr = (
unsigned short *)(
body + 44 + i * 10);
268 unsigned char layer = ((
unsigned char)
body[44 + i * 10]) & 0x0F;
269 unsigned char echo = ((
unsigned char)
body[44 + i * 10]) >> 4;
273 hAngle = (2.f * M_PI / numSteps) * (
short)ushortptr[1];
274 rDist = 0.01 * ushortptr[2];
278 laserscan[layer].
addPoint(scanPoint);
VISP_EXPORT double measureTimeSecond()
error that can be emited by ViSP classes.
Implements a laser scan data structure that contains especially the list of scanned points that have ...
Class that defines a single laser scanner point.
void setStartAngle(const short &start_angle)
void setNumPoints(const unsigned short &num_points)
static double rad(double deg)
void resize(unsigned int i, bool flagNullify=true)
void setPort(int com_port)
void setEndTimestamp(const double &end_timestamp)
void setNumSteps(const unsigned short &num_steps)
bool measure(vpLaserScan laserscan[4])
void addPoint(const vpScanPoint &p)
void setStartTimestamp(const double &start_timestamp)
void setMeasurementId(const unsigned short &id)
void setPolar(double r_dist, double h_angle, double v_angle)
void setStopAngle(const short &stop_angle)
void setIpAddress(std::string ip_address)