Comments (17)
That sounds right to me. I imagine something like moveit_core::get_logger() -> rclcpp::Logger
which can be called from anywhere to get a logger to be used locally and a way to set that from something ros specific in main function or core constructor, e.g. moveit_ros::set_logger(my_node->get_logger())
which internally might call moveit_core::set_logger()
.
from moveit2.
I can see @mlautman has further ideas and change suggestions however I don't think we'll be able to put more time into this in the short term since we want to move forward. I let @mlautman, @davetcoleman and others submit further improvements if you consider them necessary. Upcoming submodules ported will include the changes discussed above.
@vmayoral I may have been being overly critical. I think the prototypes at #21 (comment) and #33 offer a good path forward and if the logging infrastructure changes in the future, we can reassess.
from moveit2.
Thanks for the input @wjwwood.
@davetcoleman as pointed out at #7 (comment), I think we should address this issue in a separate PR since it'll touch submodules of several of the packages. I presume that changes will need to be made in moveit_ros
package, right?
It'll be really helpful to get the logging somewhat addressed before we port the rest of the code. @davetcoleman since you know best the code, can you make an initial prototype extending MoveGroup main
function while following the guidelines of @wjwwood? That'll speed things up significantly on our side.
from moveit2.
I don't think I'll be able to get to this in the next week due to travel, and I don't think I'm the most qualified to prototype this for ROS2.
from moveit2.
@davetcoleman, we finished a prototype in the kinematic_contraints submodule available at https://github.com/AcutronicRobotics/moveit2/blob/master/moveit_core/kinematic_constraints/src/kinematic_constraint.cpp#L52 and used across the code as https://github.com/AcutronicRobotics/moveit2/blob/master/moveit_core/kinematic_constraints/src/kinematic_constraint.cpp#L131.
We are systematically porting packages while verifying that things compile (as opposed to porting changes across all moveit2 packages, we don't know the code well enough to be doing so confidently and such ).
Given the discussion above where you'd like to have a global variable (I guess in MoveGroup from what's been discussed in other threads), this approach won't the final however it'll be easily changed in the future and makes now use of RCLPP APIs which will hopefully unblock several PRs which are pending such as #7 or #9.
Let me know if that's acceptable and we'll get it done.
from moveit2.
Thanks for putting together this prototype! I'd like some level of buy in from @wjwwood but it seems good to me.
To keep our style guideline roughly the same in moveit2 (see the ROS section of that page), I'd like to keep the namespace variable the same name of LOGNAME
. Its also more space efficient.
In this new approach you're proposing, I assume you'll also delete your logging.h ? I was actually a fan of that approach as it would minimize the diff, for now, between ROS1 & 2. Though that isn't super important to me.
Rather than links to lines of code, it's easiest to discuss the proposed change in a PR that targets logging, could you all do that please?
from moveit2.
Looks fine to me, only thing I'd say is that the global logger may also be static
and const
.
from moveit2.
(copied and heavily modified from #12 )
According to the ROS/Google style guides, "Objects with static storage duration are forbidden unless they are trivially destructible." It would seem that a global logger like the one in the kinematic_constraints example would violate that. (see: http://wiki.ros.org/CppStyleGuide#Globals,
https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables)
I think we can still use constexpr
and store the name as char*
's at the top of the cpp's and create loggers as needed.
I think a good rule would be to use class variables for loggers whenever possible. When this is not possible, we should be generating the logger on the fly from c-style strings with eg RCUTILS_LOG_INFO(LOGNAME, "....");
.
from moveit2.
I finished changing all the submodules of moveit_core in our master branch to the logging primitives recommended by @wjwwood. Changes follow from the prototype presented before at #21 (comment).
This took quite a bit of time and effort.
To keep our style guideline roughly the same in moveit2 (see the ROS section of that page), I'd like to keep the namespace variable the same name of LOGNAME. Its also more space efficient.
I went through the style guide and will keep it in mind. Do you intent do have a const variable only used once to define the logger? Even if that complies with the current style, I'd argue that it can probably change as well. Specially, given the fact that the whole logging structure (and how it's used) has also changed. Maybe I'm missing something and I don't quite see how you'd like to have this so I leave it up to you.
I can see @mlautman has further ideas and change suggestions however I don't think we'll be able to put more time into this in the short term since we want to move forward. I let @mlautman, @davetcoleman and others submit further improvements if you consider them necessary. Upcoming submodules ported will include the changes discussed above.
from moveit2.
From the style guide:
As a rule of thumb: a global variable satisfies these requirements if its declaration, considered in isolation, could be constexpr.
This implies to me that std::string
and therefore rclcpp::Logger
should be ok to have static storage. It would be possible to make it constexpr
if you were allowed to allocate memory for constexpr
expressions (something that is being worked on, see: https://github.com/ldionne/wg21/blob/master/generated/p1004r1.pdf / https://www.youtube.com/watch?v=CRDNPwXDVp0&feature=youtu.be&t=3080).
At any rate, I think it's safe and more efficient to statically create the logger object rather than statically store a char *
and create a logger each time you need it (each time you create a logger from a char *
a memory allocation may need to occur). However, in practice the SBO for std::string may save you most of the performance cost.
It's up to you guys.
from moveit2.
I'm frustrated by the lack of tangible PRs to have these discussions on - links to code is much more difficult to iterate on and discuss inline. I re-reviewed all the discussions so far on logging am proposing a simple example that I believe scales easily to the whole code base:
Feel free to comment inline there if you see issues with it. Or make a new PR with an alternative suggestion.
from moveit2.
Copied from: #43 (comment)
I believe we settled on const rclcpp:Logger LOGGER
in general.
For class specific loggers in files with multiple loggers const rclcpp:Logger ROBOT_STATE_LOGGER
would work as well.
For logger namespacing, we should keep the "moveit.
prefix. So the logger in RobotState might have a logger:
const rclcpp:Logger LOGGER = rclcpp::get_logger("moveit.robot_state")
And if there is a reason to use a child logger:
// within the method
rclcpp:Logger some_method_logger = LOGGER.get_child("some_method_name")
// outside the method
const rclcpp:Logger SOME_METHOD_LOGGER = LOGGER.get_child("some_method_name")
from moveit2.
const rclcpp:Logger LOGGER = rclcpp::get_logger("moveit.robot_state")
I'd suggest this small alteration:
const rclcpp:Logger LOGGER = rclcpp::get_logger("moveit").get_child("robot_state");
In case we ever change the separator.
from moveit2.
Added @wjwwood's feedback 4caa947 however note that I've omitted the const
at the beginning.
Including it causes the following error which I haven't spent time debugging:
/Users/victor/ros2_moveit_ws/src/moveit2/moveit_core/robot_state/src/conversions.cpp:62:5: error: static_assert failed due to requirement '::std::is_same<typename std::remove_reference<decltype(LOGGER)>::type, typename ::rclcpp::Logger>::value' "First argument to logging macros must be an rclcpp::Logger"
RCLCPP_ERROR(LOGGER, "Different number of names and positions in JointState message: %zu, %zu",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/victor/ros2_ws/install/rclcpp/include/rclcpp/logging.hpp:411:3: note: expanded from macro 'RCLCPP_ERROR'
static_assert( \
^
/Users/victor/ros2_moveit_ws/src/moveit2/moveit_core/robot_state/src/conversions.cpp:78:5: error: static_assert failed due to requirement '::std::is_same<typename std::remove_reference<decltype(LOGGER)>::type, typename ::rclcpp::Logger>::value' "First argument to logging macros must be an rclcpp::Logger"
RCLCPP_ERROR(LOGGER, "Different number of names, values or frames in MultiDOFJointState message.");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/victor/ros2_ws/install/rclcpp/include/rclcpp/logging.hpp:411:3: note: expanded from macro 'RCLCPP_ERROR'
static_assert( \
^
/Users/victor/ros2_moveit_ws/src/moveit2/moveit_core/robot_state/src/conversions.cpp:100:9: error: static_assert failed due to requirement '::std::is_same<typename std::remove_reference<decltype(LOGGER)>::type, typename ::rclcpp::Logger>::value' "First argument to logging macros must be an rclcpp::Logger"
RCLCPP_ERROR(LOGGER, "Caught %s", ex.what());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from moveit2.
Including it causes the following error which I haven't spent time debugging:
I think that's a bug in our template magic that supposed to detect when you're passing something other than a logger and instead should give a better error.
It needs to be updated to remove const-ness before comparing with std::is_same
.
I just made a new issue for it here: ros2/rclcpp#679
It would be a good first contribution to rclcpp
if anyone has time for it :)
from moveit2.
ros2/rclcpp#680 fixes it. Thanks @wjwwood.
from moveit2.
Added migration instructions to https://github.com/ros-planning/moveit2/blob/master/doc/MIGRATION_GUIDE.md
from moveit2.
Related Issues (20)
- Load only 1 joint-model-group kinematics solver from the srdf HOT 1
- Issue with Moveit Setup Assistant
- Moveit Servo - `publish_joint_accelerations` not working with `std_msgs/Float64MultiArray` output type HOT 1
- demo.launch.py requires a display even when setting use_rviz:=false HOT 2
- moveit_core build failed on freshly installed ROS2 Humble in WSL2 HOT 1
- No kinematics plugins defined. Fill and load kinematics.yaml! HOT 1
- moveit servo : Link 'panda_link8' not found in model 'ur10' HOT 5
- Trajectory end-point deviates too much from goal state error in panda moveit2 pick and place tutorial by picknik HOT 3
- Humble: MoveIt2 Getting Started Tutorial - colcon build failed(moveit_kinematics) HOT 4
- /clear_octomap service does not update the octomap properly in MoveIt2 HOT 2
- TM5-900 "No kinematics plugins defined." and "Failed to call service get_planning_scene" HOT 1
- Cancelling /execute_trajectory action doesn't result in stopping motion HOT 1
- Tutorial file doesn't exist: `moveit_ros/moveit_servo/launch/servo_example.launch.py`
- Removing AttachedCollisionObject is slow HOT 1
- Not being able to select ompl planners when using a name other than "manipulator" in moveit setup assistant HOT 1
- Action server: /recognize_objects not available HOT 4
- Hybrid Motion Planning
- Re-enable `planning_scene_monitor.test.py` test after diagnosing its flaky bring-up
- Namespace collision with plugin factory for class rviz_default_plugins::displays::InteractiveMarkerDisplay.
- Bullet collision checking not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moveit2.