Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wolf_ros_node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
mobile_robotics
wolf_projects
wolf_ros
wolf_ros_node
Commits
14f594e6
Commit
14f594e6
authored
4 years ago
by
Joan Vallvé Navarro
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
e17f809b
No related branches found
No related tags found
1 merge request
!5
Draft: Resolve "Single thread + profiling"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/node.h
+8
-6
8 additions, 6 deletions
include/node.h
src/node.cpp
+53
-5
53 additions, 5 deletions
src/node.cpp
with
61 additions
and
11 deletions
include/node.h
+
8
−
6
View file @
14f594e6
...
@@ -48,10 +48,18 @@ class WolfRosNode
...
@@ -48,10 +48,18 @@ class WolfRosNode
//wolf problem
//wolf problem
ProblemPtr
problem_ptr_
;
ProblemPtr
problem_ptr_
;
// solver
SolverManagerPtr
solver_
;
bool
compute_cov_
;
SolverManager
::
CovarianceBlocksToBeComputed
cov_enum_
;
ros
::
Time
last_cov_stamp_
;
double
cov_period_
;
// ROS node handle
// ROS node handle
ros
::
NodeHandle
nh_
;
ros
::
NodeHandle
nh_
;
double
viz_period_
;
double
viz_period_
;
double
solve_period_
;
// visualizer
// visualizer
std
::
shared_ptr
<
Visualizer
>
viz_
;
std
::
shared_ptr
<
Visualizer
>
viz_
;
...
@@ -62,12 +70,6 @@ class WolfRosNode
...
@@ -62,12 +70,6 @@ class WolfRosNode
std
::
vector
<
PublisherPtr
>
publishers_
;
std
::
vector
<
PublisherPtr
>
publishers_
;
protected:
protected:
// solver
SolverManagerPtr
solver_
;
bool
compute_cov_
;
SolverManager
::
CovarianceBlocksToBeComputed
cov_enum_
;
ros
::
Time
last_cov_stamp_
;
double
cov_period_
;
// transforms
// transforms
tf
::
TransformBroadcaster
tfb_
;
tf
::
TransformBroadcaster
tfb_
;
...
...
This diff is collapsed.
Click to expand it.
src/node.cpp
+
53
−
5
View file @
14f594e6
...
@@ -39,6 +39,7 @@ WolfRosNode::WolfRosNode()
...
@@ -39,6 +39,7 @@ WolfRosNode::WolfRosNode()
// SOLVER
// SOLVER
ROS_INFO
(
"Creating solver..."
);
ROS_INFO
(
"Creating solver..."
);
solver_
=
FactorySolver
::
create
(
"SolverCeres"
,
problem_ptr_
,
server
);
solver_
=
FactorySolver
::
create
(
"SolverCeres"
,
problem_ptr_
,
server
);
solve_period_
=
server
.
getParam
<
double
>
(
"solver/period"
);
// covariance
// covariance
compute_cov_
=
server
.
getParam
<
bool
>
(
"solver/compute_cov"
);
compute_cov_
=
server
.
getParam
<
bool
>
(
"solver/compute_cov"
);
if
(
compute_cov_
)
if
(
compute_cov_
)
...
@@ -199,7 +200,7 @@ void WolfRosNode::broadcastTf()
...
@@ -199,7 +200,7 @@ void WolfRosNode::broadcastTf()
tfb_
.
sendTransform
(
current_map2odom
);
tfb_
.
sendTransform
(
current_map2odom
);
}
}
void
WolfRosNode
::
solveLoop
()
/*
void WolfRosNode::solveLoop()
{
{
ros::Rate solverRate(1/(solver_->getPeriod()+1e-9)); // 1ns added to allow pausing if rosbag paused
ros::Rate solverRate(1/(solver_->getPeriod()+1e-9)); // 1ns added to allow pausing if rosbag paused
WOLF_DEBUG("Started solver loop");
WOLF_DEBUG("Started solver loop");
...
@@ -215,7 +216,7 @@ void WolfRosNode::solveLoop()
...
@@ -215,7 +216,7 @@ void WolfRosNode::solveLoop()
solverRate.sleep();
solverRate.sleep();
}
}
WOLF_DEBUG("Solver loop finished");
WOLF_DEBUG("Solver loop finished");
}
}
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
...
@@ -230,14 +231,18 @@ int main(int argc, char **argv)
...
@@ -230,14 +231,18 @@ int main(int argc, char **argv)
ros
::
Time
last_viz_time
=
ros
::
Time
(
0
);
ros
::
Time
last_viz_time
=
ros
::
Time
(
0
);
ros
::
Time
last_solve_time
=
ros
::
Time
(
0
);
ros
::
Time
last_solve_time
=
ros
::
Time
(
0
);
// Solver thread
/*
// Solver thread
std::thread solver_thread(&WolfRosNode::solveLoop, &wolf_node);
std::thread solver_thread(&WolfRosNode::solveLoop, &wolf_node);
// set priority
// set priority
struct sched_param Priority_Param; //struct to set priority
struct sched_param Priority_Param; //struct to set priority
int priority = 99;
int priority = 99;
Priority_Param.sched_priority = priority;
Priority_Param.sched_priority = priority;
int policy=SCHED_FIFO;
int policy=SCHED_FIFO;
pthread_setschedparam
(
solver_thread
.
native_handle
(),
SCHED_FIFO
,
&
Priority_Param
);
pthread_setschedparam(solver_thread.native_handle(), SCHED_FIFO, &Priority_Param);*/
// Profiling
double
duration_viz
(
0
),
duration_solver
(
0
);
unsigned
int
n_viz
(
0
),
n_solver
(
0
);
while
(
ros
::
ok
())
while
(
ros
::
ok
())
{
{
...
@@ -246,12 +251,16 @@ int main(int argc, char **argv)
...
@@ -246,12 +251,16 @@ int main(int argc, char **argv)
wolf_node
.
broadcastTf
();
wolf_node
.
broadcastTf
();
// visualize periodically
// visualize periodically
auto
start3
=
std
::
chrono
::
high_resolution_clock
::
now
();
if
((
ros
::
Time
::
now
()
-
last_viz_time
).
toSec
()
>=
wolf_node
.
viz_period_
)
if
((
ros
::
Time
::
now
()
-
last_viz_time
).
toSec
()
>=
wolf_node
.
viz_period_
)
{
{
auto
start
=
std
::
chrono
::
high_resolution_clock
::
now
();
//std::cout << "Last Viz since/viz_period_ " << (ros::Time::now() - last_viz_time).toSec() << " / " << wolf_node.viz_period_ << std::endl;
//std::cout << "Last Viz since/viz_period_ " << (ros::Time::now() - last_viz_time).toSec() << " / " << wolf_node.viz_period_ << std::endl;
wolf_node
.
visualize
();
wolf_node
.
visualize
();
last_viz_time
=
ros
::
Time
::
now
();
last_viz_time
=
ros
::
Time
::
now
();
duration_viz
+=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
std
::
chrono
::
high_resolution_clock
::
now
()
-
start
);
n_viz
++
;
}
}
// publish periodically
// publish periodically
...
@@ -259,6 +268,13 @@ int main(int argc, char **argv)
...
@@ -259,6 +268,13 @@ int main(int argc, char **argv)
if
(
pub
->
ready
())
if
(
pub
->
ready
())
pub
->
publish
();
pub
->
publish
();
// solve periodically
if
((
ros
::
Time
::
now
()
-
last_solve_time
).
toSec
()
>
wolf_node
.
solve_period_
)
{
wolf_node
.
solve
();
last_solve_time
=
ros
::
Time
::
now
();
}
// execute pending callbacks
// execute pending callbacks
ros
::
spinOnce
();
ros
::
spinOnce
();
...
@@ -269,6 +285,38 @@ int main(int argc, char **argv)
...
@@ -269,6 +285,38 @@ int main(int argc, char **argv)
solver_thread
.
join
();
solver_thread
.
join
();
WOLF_DEBUG
(
"thread stopped."
);
WOLF_DEBUG
(
"thread stopped."
);
// Profiling
ofstream
profiling_file
;
profiling_file
.
open
(
"~/wolf_profiling.txt"
);
profiling_file
<<
"WOLF PROFILING:
\n
"
;
profiling_file
<<
"
\n\n
SOLVER:"
<<
"
\n\t
total time:"
<<
wolf_node
.
solver_
.
duration_manager_
+
wolf_node
.
solver_
.
duration_solver_
<<
" s"
<<
"
\n\t
manager time:"
<<
wolf_node
.
solver_
.
duration_manager_
<<
" s"
<<
"
\n\t
solver time:"
<<
wolf_node
.
solver_
.
duration_solver_
<<
" s"
<<
"
\n\t
executions:"
<<
wolf_node
.
solver_
.
n_solve_
<<
"
\n\t
average time:"
<<
(
wolf_node
.
solver_
.
duration_manager_
+
wolf_node
.
solver_
.
duration_solver_
)
/
wolf_node
.
solver_
.
n_solve_
<<
" s"
<<
"
\n\t
average manager time:"
<<
wolf_node
.
solver_
.
duration_manager_
/
wolf_node
.
solver_
.
n_solve_
<<
" s"
<<
"
\n\t
average solver time:"
<<
wolf_node
.
solver_
.
duration_solver_
/
wolf_node
.
solver_
.
n_solve_
<<
" s"
<<
std
::
endl
;
profiling_file
<<
"
\n\n
VISUALIZATION:"
<<
"
\n\t
total time:"
<<
duration_viz
<<
" s"
<<
"
\n\t
executions:"
<<
n_viz
<<
"
\n\t
average time:"
<<
duration_viz
/
n_viz
<<
std
::
endl
;
for
(
auto
sensor
:
wolf_node
.
problem_ptr_
->
getHardware
()
->
getSensorList
())
for
(
auto
proc
:
sensor
->
getProcessorList
())
{
profiling_file
<<
"
\n\n
PROCESSOR "
<<
proc
->
getName
()
<<
":"
<<
"
\n\t
total time:"
<<
wolf_node
.
solver_
.
duration_manager_
+
wolf_node
.
solver_
.
duration_solver_
<<
" s"
<<
"
\n\t
proc. captures time:"
<<
wolf_node
.
solver_
.
duration_manager_
<<
" s"
<<
"
\n\t
proc. frames time:"
<<
wolf_node
.
solver_
.
duration_solver_
<<
" s"
<<
"
\n\t
executions:"
<<
wolf_node
.
solver_
.
n_solve_
<<
"
\n\t
average time:"
<<
(
wolf_node
.
solver_
.
duration_manager_
+
wolf_node
.
solver_
.
duration_solver_
)
/
wolf_node
.
solver_
.
n_solve_
<<
" s"
<<
"
\n\t
average proc. captures time:"
<<
wolf_node
.
solver_
.
duration_manager_
/
wolf_node
.
solver_
.
n_solve_
<<
" s"
<<
"
\n\t
average proc. frames time:"
<<
wolf_node
.
solver_
.
duration_solver_
/
wolf_node
.
solver_
.
n_solve_
<<
" s"
<<
std
::
endl
;
}
profiling_file
.
close
();
return
0
;
// file.close();
// file.close();
return
0
;
return
0
;
}
}
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