38 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
40 #include <visp3/sensor/vpSickLDMRS.h>
41 #include <visp3/core/vpMath.h>
42 #include <visp3/core/vpDebug.h>
43 #include <visp3/core/vpTime.h>
44 #include <sys/socket.h>
45 #include <sys/select.h>
46 #include <netinet/in.h>
73 : socket_fd(-1), body(NULL), vAngle(), time_offset(0),
74 isFirstMeasure(true), maxlen_body(104000)
76 ip =
"131.254.12.119";
109 return ( this->
setup() );
119 struct sockaddr_in serv_addr;
125 socket_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
127 fprintf(stderr,
"Failed to create socket\n");
131 memset(&serv_addr, 0,
sizeof(serv_addr));
132 serv_addr.sin_family = AF_INET;
133 serv_addr.sin_addr.s_addr = inet_addr(
ip.c_str());
134 serv_addr.sin_port = htons(
port);
137 res = connect(
socket_fd, (
struct sockaddr *)&serv_addr,
sizeof(serv_addr)) ;
138 if (errno == EINPROGRESS) {
142 FD_SET(static_cast<unsigned int>(
socket_fd), &myset);
143 res = select(
socket_fd+1, NULL, &myset, NULL, &tv);
144 if (res < 0 && errno != EINTR) {
145 fprintf(stderr,
"Error connecting to server %d - %s\n", errno, strerror(errno));
149 fprintf(stderr,
"ok");
152 fprintf(stderr,
"Timeout in select() - Cancelling!\n");
168 unsigned int *uintptr;
169 unsigned short *ushortptr;
170 static unsigned char header[24];
171 ushortptr=(
unsigned short *)header;
172 uintptr=(
unsigned int *)header;
174 assert (
sizeof(header) == 24);
177 double time_second = 0;
184 if (recv(
socket_fd, header,
sizeof(header), MSG_WAITALL) == -1) {
191 printf(
"Error, wrong magic number !!!\n");
196 uint16_t msgtype = ntohs(ushortptr[7]);
197 uint32_t msgLength = ntohl(uintptr[2]);
200 if (len != (ssize_t)msgLength){
201 printf(
"Error, wrong msg length: %d of %d bytes.\n", (
int)len, msgLength);
213 unsigned short measurementId;
214 ushortptr = (
unsigned short *)
body;
215 measurementId = ushortptr[0];
218 uintptr=(
unsigned int *) (
body+6);
219 unsigned int seconds = uintptr[1];
220 unsigned int fractional=uintptr[0];
221 double startTimestamp = seconds + fractional / 4294967296.;
224 uintptr=(
unsigned int *) (
body+14);
225 seconds = uintptr[1];
226 fractional=uintptr[0];
227 double endTimestamp = seconds + fractional / 4294967296.;
239 unsigned short numSteps = ushortptr[11];
242 short startAngle = (short)ushortptr[12];
243 short stopAngle = (short)ushortptr[13];
248 unsigned short numPoints = ushortptr[14];
251 for (
int i=0; i < nlayers; i++) {
252 laserscan[i].
clear();
267 if (numPoints > USHRT_MAX-2)
270 for (
int i=0; i < numPoints; i++) {
271 ushortptr = (
unsigned short *) (
body+44+i*10);
272 unsigned char layer = ((
unsigned char)
body[44+i*10])&0x0F;
273 unsigned char echo = ((
unsigned char)
body[44+i*10])>>4;
277 hAngle = (2.f * M_PI / numSteps)*(
short) ushortptr[1];
278 rDist = 0.01 * ushortptr[2];
282 laserscan[layer].
addPoint(scanPoint);
VISP_EXPORT double measureTimeSecond()
error that can be emited by ViSP classes.
The magic word that allows to identify the messages that are sent by the Sick LD-MRS.
Implements a laser scan data structure that contains especially the list of scanned points that have ...
Class that defines a single laser scanner point.
Flag to indicate that the body of a message contains measured data.
void setStartAngle(const short &start_angle)
void setNumPoints(const unsigned short &num_points)
static double rad(double deg)
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)
void resize(const unsigned int i, const bool flagNullify=true)