-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[joint_state_controller/broadcaster] "Resorted" joint_names compared to URDF/xacro file #159
Comments
I think, you are pointing at,
I will take a look at this. Please feel free to assign me this issue. |
@destogl wrote:
why? This has been discussed in the past, and it makes everything much more robust if nodes/controllers/plugins/whatever don't/can't assume a certain order. There are so many producers and consumers of (fi) I'd suggest making the requirement for consumers to always re-order (ie: preprocess/validate user input) incoming information as they need it explicit instead of the implicit assumption we have now (in |
@destogl , please find the observation below, While listing the hardware interfaces, printing the interface names at this line
So, it is clear that in generic_system.cpp file, everything is in order. Found the output below while launch. Added log at line 123 and line 136
Observe the sequence of Line 138 is exactly same as the output of the Note : The joint names are in order in ros2_control_demos/ros2_control_demo_robot/description/6Dbot/6Dbot_macro.ros2_control.xacro file. |
@bailaC can you also check this in the assigned interfaces method? See the first comment, point Nr. 3 |
Yes, sure, I missed that. |
Collecting the output from both
Everything is at one place now. |
Can you make print also with "interface.get_name() + interface.get_interface_name()" |
Heads up: I've just merged |
* make gh actions on pair with ros2_controllers Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * rename jobs Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * remove codecov Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * limit source job to foxy distribution Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * rename binary job Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * list packages explicitly Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * add main repos Signed-off-by: Karsten Knese <Karsten1987@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Denis Štogl <destogl@users.noreply.github.com> Co-authored-by: Denis Štogl <destogl@users.noreply.github.com>
This is something I have seen before as well. Not sure if it's the same issue that is happening, but I believe that it has to do with something that happens here: ros2_controllers/joint_state_broadcaster/src/joint_state_broadcaster.cpp Lines 253 to 260 in 219a121
By looping over an unordered map, the order of the joints in the /joint_states is not sorted. I'm not sure how it iterates over an unordered map, but in my project we have now tried changing it to a regular This leads to the /joint_states topic being sorted alphabetically by joint name Maybe there's a more elegant way to implement this but this was a bit of a quick hack to get it working. |
That is a good hint, it seems that you have found the culprit. The question for me is now, should it be in alphabetical order or in the order of definition in the parameters? If the latter is the case, then we have to use something like a std::vector instead. |
Anything but the current setup would be an improvement. |
we have two configurations:
for the first I'd say, use the same order as in the parameter. |
Would it not make sense to put it in order of the kinematic chain (if possible)? This would simplify Jacobian computations and what not. Hope I am not missing something. |
i have a problem with joints name on the topic /joint_states , in particular i wish would :
but i have:
The order of links and joints in the axcro file robot.model.xacro is correct from base to last joint , in robot.ros2_control.xacro where declared che command and state interfaces the order of joints is joint1 to joint6 and in the file ros2_controllers.yaml i defined :
how can i fix this order on the topic /joint_states? |
You'd need to tweak how the list of joint names are created here: As it was said here before, you could take a new (optional) parameter for the joint state broadcaster to specify the order of joints but do put some thought into how you'd want to handle discrepancies in the number of available joints vs the list provided? Also as @mhubii said, the kinematics order sounds very nice but then you'd need to grab the URDF and figure out what that order is. Also, kinematics from where to where? ;) You can be fairly liberal with the implementation here, no need to worry about realtime as the function I referenced runs before the |
If you go here you can see what we changed in order to get it alphabetical. Essentially it was changing the type from an in the
and in the
Hope that's clear, and can help you fix it. In the end we moved away from the Joint state broadcaster completely and made our own broadcaster as we had created a custom fork of the JSB and were sometimes sourcing the wrong one (without alphabetical sorting), leading to some interesting results. should I make a pull request with this fix? |
That's a very good point, had only considered simple chains. Might there be room for another broadcaster then? Something along the lines of a serial chain joint state broadcaster? |
if we change the unordered map, you always can give the |
@martijnhabers In my experience it is always better to discuss implementation details on PRs ;) |
well either ordered way is fine really. Extracting the order from the chain may offer a unique source and default initialization with robustness to prefixes at the cost of introducing complexity and entanglement. |
Do the PR pls |
IMO Introducing kinematics chains into JSB will just make the code complex. Better start with the ordering part for the defined joints parameter. |
I just checked the code, i think changing unorderd_map to map won't fix anything. What needs to be fixed is the order of names in the This is what is used in the |
I have doing your change to file joint_state_broadcaster.cpp e joint_state_broadcaster.hpp and finally the joints name are in roder from 1 to 6. Thanks for the tips and thanks also all everyone others !!! |
@mhubii I think there is a way we could have the cake and eat it. I mean, what if we had 2 JSB instances in a system? And by we I mean you, or anyone who wants to have it published in a specific order for some specific chain?
Would this work? |
TLDR;
Would be very helpful indeed (this should ideally be supported (lbr-stack/lbr_fri_ros2_stack#178 (comment)), and this seems to be the conses here:
But one might consider an additional kinematic chain broadcaster in another issue. Now, instead of talking, I also agree with
Details
yes would totally work of course :). Any solution that driver maintainers can support such that users of that driver don't run into that same pitfall over and over. It does happen a lot that users send commands and then the robot does funky stuff which is ultimately dangerous. That's why I was thinking of leaving the JSB untouched
I.e. provide an alternative maybe inherited JSB with access to chain. This doesn't seem much more complex than the admittance controller, and I am of course coming from a serial manipulator standpoint. Again, I see this argument
However, I don't think it will "just" make the code complex. It will provide benefits indeed as explained above. Let me make this clearer. Downstream I see a lot of this, and this does assume at least alphabetical sorting (and even worse, I don't see it) def _on_joint_state(self, joint_state: JointState) -> None:
q = np.array(joint_state.position)[np.argsort(joint_state.name)]
# dq = J(q)^(-1)@dx ... Is having an
but that defeats the purpose imho. The alphabetical sorting assumption may already break for people building on top of drivers... You can of course now argue that I am using |
@antrom99 @mhubii @martijnhabers, Could you please give my changes in PR a shot at #1572 and see if they improve now? Thank you |
Hello! I can confirm that the fix proposed in #1572 is working |
I just got reported that the
joint_state_controller
hasresorted
joint_names compared to theros2_control
-tag defined in the URDF file. They could be confusing and we should "debug" this if possible.For this, I propose the following procedure:
ros2_control_demos
repository6Dbot-example-for-tests
branch (Add example 6Dbot for tests and debugging ros2_control_demos#74).ros2 launch ros2_control_demo_robot 6Dbot_example.launch.py
/joint_states
topics and see that the name field does not start with "joint1", but "joint2". Why? This has to be answered in this issue!state_interfaces
in theassign_interfaces
method here.joint_names_
variable here.If the joint_names are mixed, we have to find out exactly where to know if this is repairable or add additional parameters or parsing of URDF in the controller.
The text was updated successfully, but these errors were encountered: