Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LidarView-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LidarView
LidarView-Core
Commits
047d48db
Commit
047d48db
authored
8 years ago
by
Pierre Guilbert
Browse files
Options
Downloads
Patches
Plain Diff
Bugfix packetfilesender
parent
40939768
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
VelodyneHDL/PacketFileSender.cxx
+31
-15
31 additions, 15 deletions
VelodyneHDL/PacketFileSender.cxx
with
31 additions
and
15 deletions
VelodyneHDL/PacketFileSender.cxx
+
31
−
15
View file @
047d48db
...
...
@@ -35,7 +35,9 @@
#include
<string>
#include
<cstdlib>
#include
<iostream>
#include
<chrono>
#include
<ctime>
#include
<thread>
#include
<boost/thread/thread.hpp>
int
main
(
int
argc
,
char
*
argv
[])
...
...
@@ -70,6 +72,21 @@ int main(int argc, char* argv[])
speed
=
static_cast
<
double
>
(
atof
(
argv
[
6
]));
}
//The sensor send one packet every 553 microseconds
int
timeToWait
=
static_cast
<
int
>
(
1
/
speed
*
553
);
//The timers resolution is only 1000 microsecond
//But we need to send packets every 553 microseconds
//Thus, we send packet by group of 100 and then wait
//55 300 microseconds
int
NumberPacketsByPool
=
20
;
//Calibration of the sleep
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
T1
,
T2
;
std
::
chrono
::
duration
<
double
>
elapsedTime
;
double
timeMicroSecond
=
0
;
std
::
cout
<<
"Start sending"
<<
std
::
endl
;
try
{
do
...
...
@@ -79,25 +96,24 @@ int main(int argc, char* argv[])
bool
isFirstPacket
=
true
;
double
currentTimeStamp
=
0
;
double
previousTimeStamp
=
0
;
double
timeToWait
=
0
;
while
(
!
sender
.
done
())
{
currentTimeStamp
=
sender
.
pumpPacket
();
//timeToWait is the elapsed time between the packets (n-1) and n
//It is used to wait before sending the packet n+1
//Hence, there is an offset.
timeToWait
=
((
currentTimeStamp
-
previousTimeStamp
)
*
1e6
)
/
speed
;
previousTimeStamp
=
currentTimeStamp
;
if
(
isFirstPacket
)
sender
.
pumpPacket
();
if
((
sender
.
packetCount
()
%
1000
)
==
0
)
{
isFirstPacket
=
false
;
timeToWait
=
200
;
T2
=
std
::
chrono
::
high_resolution_clock
::
now
();
elapsedTime
=
T2
-
T1
;
std
::
cout
<<
"total sent packets : "
<<
sender
.
packetCount
();
std
::
cout
<<
" Elapsed time per packets : "
<<
elapsedTime
.
count
()
*
1e6
/
1000
<<
" microsecond"
<<
std
::
endl
;
T1
=
std
::
chrono
::
high_resolution_clock
::
now
();
//printf("total sent packets: %lu\t, time between packets : %f\n", sender.packetCount(),timeToWait/1e6);
}
if
((
sender
.
packetCount
()
%
500
)
==
0
)
//boost::this_thread::sleep(boost::posix_time::microseconds(553));
if
((
sender
.
packetCount
()
%
NumberPacketsByPool
)
==
0
)
{
printf
(
"total sent packets: %lu
\t
, time between packets : %f
\n
"
,
sender
.
packetCount
(),
timeToWait
/
1e6
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
microseconds
(
NumberPacketsByPool
*
timeToWait
)
);
}
boost
::
this_thread
::
sleep
(
boost
::
posix_time
::
microseconds
(
timeToWait
));
}
}
while
(
loop
);
}
...
...
@@ -108,4 +124,4 @@ int main(int argc, char* argv[])
}
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment