Skip to content
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

Use ros2 control with sdf model #632

Open
karimrahimi76 opened this issue Jan 31, 2022 · 11 comments · May be fixed by #1763
Open

Use ros2 control with sdf model #632

karimrahimi76 opened this issue Jan 31, 2022 · 11 comments · May be fixed by #1763

Comments

@karimrahimi76
Copy link

hi , i am trying to use ros2 control for a parallel robot , and my model is sdf format.
when i want to launch a project , controller manager needs robot description. but sdf format has no any robot tag.
even i tried to pass my project world and sdf format to controller manager, but it doesn't work too.

would anybody mind Is ros2 control works with sdf format?
how can I handle it?

@destogl
Copy link
Member

destogl commented Jan 31, 2022

Hi @karimrahimi76,

We are currently working with URDF file format, which is standard for ROS visualization/simulation/manipulation. Is there a reason you cannot use URDF format? How are you then visualizing your robot in rviz? To be sure to work with ros2_control try to define URDF format and give it to the controller manager node. As a first step, you don't need any geometric description, but you can only provide <ros2_control> tag as shown in our examples (check the linked files for each example.

@karimrahimi76
Copy link
Author

Hi @karimrahimi76,

We are currently working with URDF file format, which is standard for ROS visualization/simulation/manipulation. Is there a reason you cannot use URDF format? How are you then visualizing your robot in rviz? To be sure to work with ros2_control try to define URDF format and give it to the controller manager node. As a first step, you don't need any geometric description, but you can only provide <ros2_control> tag as shown in our examples (check the linked files for each example.

thank you for your response , i cannot use urdf because i want to simulate parallel robots and need "ball" joint and "universal" joint that urdf doesn't support that.
so i can not simulate my robot in urdf format and i have to do it in sdf format.

@karimrahimi76 karimrahimi76 reopened this Feb 1, 2022
@olivier-stasse
Copy link
Contributor

olivier-stasse commented Feb 1, 2022

Dear @karimrahimi76,
I do not think that this is a software problem for ros2_control itself.

In SDF with Gazebo it is needed because you need to simulate the closed kinematic chain.

On the real robot, the mechanics is doing this for you. Strictly speaking you can write a URDF allowing to load the hardware interface for accessing the low level hardware of your robot. The URDF model will not include the closed kinematic structure. So if your goal is to control your real robot with ros2_control there is no immediate problem which forbid you to do so.

The two main caveats are the following:

  • As far as I know there is no ros2_controller able to take into account the parallel mechanism, but you can write your own.
  • Using gazebo_ros2_package will be a challenge because it is using the URDF model to build the simulated model. A quick solution is to use the same URDF than for the hardware_interface, but then the impact of this constraint will not appear. Right now I do not think it is directly feasible to use your SDF file instead (but it is probably doable).

Note: this remark is only a view of my own understanding of ros2_control.

@destogl
Copy link
Member

destogl commented Feb 1, 2022

thank you for your response , i cannot use urdf because i want to simulate parallel robots and need "ball" joint and "universal" joint that urdf doesn't support that. so i can not simulate my robot in urdf format and i have to do it in sdf format.

@karimrahimi76 as I wrote… you only need to provide <ros2_control> part of URDF which is kinematics-agnostic…

@olivier-stasse thanks for the clarification. I think your observations are fully right!

@karimrahimi76
Copy link
Author

  • Using gazebo_ros2_package will be a challenge because it is using the URDF model to build the simulated model. A quick solution is to use the same URDF th

dear @olivier-stasse thank you for your attention and response.
I think you are fully right and we have too write a custom package or library for our parallel Robot.

@karimrahimi76
Copy link
Author

thank you for your response , i cannot use urdf because i want to simulate parallel robots and need "ball" joint and "universal" joint that urdf doesn't support that. so i can not simulate my robot in urdf format and i have to do it in sdf format.

@karimrahimi76 as I wrote… you only need to provide <ros2_control> part of URDF which is kinematics-agnostic…

@olivier-stasse thanks for the clarification. I think your observations are fully right!

dear @destogl
I checked the Examples and it was useful for me.
thank you for that. finally I think i have too write my custom package or plugin for my parallel Robot Close Chain Control.

@destogl
Copy link
Member

destogl commented Feb 14, 2022

dear @destogl I checked the Examples and it was useful for me. thank you for that. finally I think i have too write my custom package or plugin for my parallel Robot Close Chain Control.

The clue is that you ros2_control doesn't know anything about kinematics so you can also make it "broken" in URDF and things should work OK.

@christophfroehlich
Copy link
Contributor

I had a very similar problem, we solved it with the approach Olivier already outlined.

Just for reference:
We added all links and joints, only the last link closing the kinematic chains are within <gazebo> tags. This does not bother ros2_control.

rviz2 is fine with the full model if gazebo_ros2_control and joint_state_broadcaster publish all relevant joints describing the kinematic chains.

While deploying this stuff to the real robot, one can

  • make a urdf version without the closed-loop kinematic chains and use only the real DOFs
  • implement the kinematics in the hardware_interface and fill all relevant state_interfaces from the measurements

@christophfroehlich christophfroehlich closed this as not planned Won't fix, can't repro, duplicate, stale Mar 31, 2023
@asimonov
Copy link

asimonov commented Sep 6, 2024

can you re-open this issue?

Gazebo Harmonic allows to use SDF for robot description, instead of URDF. mentioned as last item here: https://github.com/gazebosim/gz-harmonic/blob/main/highlights.md, documentation is here https://gazebosim.org/docs/harmonic/ros2_interop/

but if I try to run this setup with ros2_control I see this:

[ros2_control_node-3] [INFO] [1725603736.262263586] [controller_manager]: Received robot description from topic.
[ros2_control_node-3] terminate called after throwing an instance of 'std::runtime_error'
[ros2_control_node-3]   what():  the robot tag is not root element in URDF
[ERROR] [ros2_control_node-3]: process has died

robot_state_publisher and joint_state_publisher work with SDF. would be nice to make ros2_control work with it too

@christophfroehlich
Copy link
Contributor

christophfroehlich commented Sep 9, 2024

Gazebo Harmonic allows to use SDF for robot description, instead of URDF. mentioned as last item here: https://github.com/gazebosim/gz-harmonic/blob/main/highlights.md, documentation is here https://gazebosim.org/docs/harmonic/ros2_interop/

but if I try to run this setup with ros2_control I see this:

[ros2_control_node-3] [INFO] [1725603736.262263586] [controller_manager]: Received robot description from topic.
[ros2_control_node-3] terminate called after throwing an instance of 'std::runtime_error'
[ros2_control_node-3]   what():  the robot tag is not root element in URDF
[ERROR] [ros2_control_node-3]: process has died

robot_state_publisher and joint_state_publisher work with SDF. would be nice to make ros2_control work with it too

I haven't tried this out, but the description says that the example is using https://github.com/ros/sdformat_urdf to create a URDF from the SDF, which is then passed to the ROS 2 world.

This could work with ros2_control, if it is possible to generate the ros2_control tags into the URDF.

We don't have plans to be able to provide SDF support inside ros2_control.

@azeey
Copy link

azeey commented Sep 24, 2024

I believe robot_state_publisher works because it doesn't parse the URDF directly. Instead, it uses urdf_parser_plugin via urdf::Model::InitString
https://github.com/ros/robot_state_publisher/blob/65e4d964e66dab348aac43053855c584dbddd620/src/robot_state_publisher.cpp#L164. This loads the sdformat_urdf plugin which populates the urdf::Model based on the SDFormat file or string. It doesn't actually generate a URDF string. I believe, overall, this is the preferred approach since it's the most flexible and can support other file formats such as Collada
image

joint_state_publisher on the other hand is a python package, so it is not able to take advantage of that plugin mechanism. Instead, it handles URDF, SDF, and Collada separately based on the root tag of the input string.

https://github.com/ros/joint_state_publisher/blob/fb29caa6a341556ef8716b583ef32507d001dcdc/joint_state_publisher/joint_state_publisher/joint_state_publisher.py#L286-L291

I see ros2_control already uses urdf_parser_plugin:

if (!model.initString(urdf))

But, I don't believe the urdfdom data structures keep extra data, such as the ros2_control tags, so it will probably have to handle SDF files separately. I think changing only a small section of code might get us there.

If we also allowed for <sdf> tag in

if (std::string(kRobotTag) != robot_it->Name())
{
throw std::runtime_error("the robot tag is not root element in URDF");

perhaps everything will "just work" 🤞🏾 .

@Amronos Amronos linked a pull request Sep 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants