Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic_graph_bridge
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
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
Guilhem Saurel
dynamic_graph_bridge
Commits
770b4d3e
Commit
770b4d3e
authored
5 years ago
by
Joseph Mirabel
Browse files
Options
Downloads
Patches
Plain Diff
Use ros::Rate and ROS logs.
parent
d17eb57b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/geometric_simu.cpp
+8
-2
8 additions, 2 deletions
src/geometric_simu.cpp
src/sot_loader.cpp
+36
-24
36 additions, 24 deletions
src/sot_loader.cpp
with
44 additions
and
26 deletions
src/geometric_simu.cpp
+
8
−
2
View file @
770b4d3e
...
...
@@ -16,15 +16,21 @@
* have received a copy of the GNU Lesser General Public License along
* with dynamic_graph_bridge. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<
i
os
tream
>
#include
<
r
os
/console.h
>
#define ENABLE_RT_LOG
#include
<dynamic-graph/real-time-logger.h>
#include
<dynamic_graph_bridge/sot_loader.hh>
class
LoggerROSStream
:
public
::
dynamicgraph
::
LoggerStream
{
public:
void
write
(
const
char
*
c
)
{
ROS_ERROR
(
c
);
}
};
int
main
(
int
argc
,
char
*
argv
[])
{
dgADD_OSTREAM_TO_RTLOG
(
std
::
cerr
);
::
dynamicgraph
::
RealTimeLogger
::
instance
()
.
addOutputStream
(
::
dynamicgraph
::
LoggerStreamPtr_t
(
new
LoggerROSStream
()));
ros
::
init
(
argc
,
argv
,
"sot_ros_encapsulator"
);
SotLoader
aSotLoader
;
...
...
This diff is collapsed.
Click to expand it.
src/sot_loader.cpp
+
36
−
24
View file @
770b4d3e
...
...
@@ -20,6 +20,7 @@
/* --- INCLUDES ------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include
<ros/rate.h>
#include
<dynamic_graph_bridge/sot_loader.hh>
#include
"dynamic_graph_bridge/ros_init.hh"
...
...
@@ -36,15 +37,27 @@ namespace po = boost::program_options;
struct
DataToLog
{
const
std
::
size_t
N
;
std
::
size_t
idx
;
std
::
size_t
idx
,
iter
;
std
::
vector
<
std
::
size_t
>
iters
;
std
::
vector
<
double
>
times
;
DataToLog
(
std
::
size_t
N_
)
:
N
(
N_
),
idx
(
0
),
times
(
N
,
0
)
{}
void
record
(
const
double
t
)
{
times
[
idx
]
=
t
;
std
::
vector
<
double
>
ittimes
;
DataToLog
(
std
::
size_t
N_
)
:
N
(
N_
)
,
idx
(
0
)
,
iter
(
0
)
,
iters
(
N
,
0
)
,
times
(
N
,
0
)
,
ittimes
(
N
,
0
)
{}
void
record
(
const
double
t
,
const
double
itt
)
{
iters
[
idx
]
=
iter
;
times
[
idx
]
=
t
;
ittimes
[
idx
]
=
itt
;
++
idx
;
++
iter
;
if
(
idx
==
N
)
idx
=
0
;
}
...
...
@@ -55,7 +68,10 @@ struct DataToLog {
std
::
ofstream
aof
(
oss
.
str
().
c_str
());
if
(
aof
.
is_open
())
{
for
(
std
::
size_t
k
=
0
;
k
<
N
;
++
k
)
{
aof
<<
times
[(
idx
+
k
)
%
N
]
<<
'\n'
;
aof
<<
iters
[(
idx
+
k
)
%
N
]
<<
' '
<<
times
[(
idx
+
k
)
%
N
]
<<
' '
<<
ittimes
[(
idx
+
k
)
%
N
]
<<
'\n'
;
}
}
aof
.
close
();
...
...
@@ -63,38 +79,34 @@ struct DataToLog {
};
void
workThreadLoader
(
SotLoader
*
aSotLoader
)
{
unsigned
period
=
1000
;
//
micro seconds
ros
::
Rate
rate
(
1000
)
;
//
1 kHz
if
(
ros
::
param
::
has
(
"/sot_controller/dt"
))
{
double
periodd
;
ros
::
param
::
get
(
"/sot_controller/dt"
,
periodd
);
period
=
unsigned
(
1e6
*
periodd
);
rate
=
ros
::
Rate
(
1
/
periodd
);
}
DataToLog
dataToLog
(
5000
);
while
(
aSotLoader
->
isDynamicGraphStopped
())
{
usleep
(
period
);
rate
.
reset
();
while
(
ros
::
ok
()
&&
aSotLoader
->
isDynamicGraphStopped
())
{
rate
.
sleep
();
}
struct
timeval
start
,
stop
;
ros
::
NodeHandle
nh
(
"/geometric_simu"
);
bool
paused
;
unsigned
long
long
dt
;
while
(
!
aSotLoader
->
isDynamicGraphStopped
())
{
ros
::
Time
timeOrigin
=
ros
::
Time
::
now
();
ros
::
Time
time
;
while
(
ros
::
ok
()
&&
!
aSotLoader
->
isDynamicGraphStopped
())
{
nh
.
param
<
bool
>
(
"paused"
,
paused
,
false
);
if
(
!
paused
)
{
get
time
ofday
(
&
start
,
0
);
time
=
ros
::
Time
::
now
(
);
aSotLoader
->
oneIteration
();
gettimeofday
(
&
stop
,
0
);
dt
=
1000000
*
(
stop
.
tv_sec
-
start
.
tv_sec
)
+
(
stop
.
tv_usec
-
start
.
tv_usec
);
dataToLog
.
record
((
double
)
dt
*
1e-6
);
}
else
dt
=
0
;
if
(
period
>
dt
)
{
usleep
(
period
-
(
unsigned
)
dt
);
ros
::
Duration
d
=
ros
::
Time
::
now
()
-
time
;
dataToLog
.
record
((
time
-
timeOrigin
).
toSec
(),
d
.
toSec
());
}
rate
.
sleep
();
}
dataToLog
.
save
(
"/tmp/geometric_simu"
);
cond
.
notify_all
();
...
...
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