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

Split the urscript into a header and a control loop. #14

Merged
merged 3 commits into from
Mar 22, 2021

Conversation

urmahp
Copy link
Contributor

@urmahp urmahp commented Feb 18, 2021

The header is only appended to the UR program once, while the control loop is appended for each urcap node. This enables the possibility to have multiple urcap nodes in one program.

This implements #5
It is related to pr #7 and UniversalRobots/Universal_Robots_ROS_Driver#207.
But it is a slightly different approach, with this approach the urscript doesn't have to be changed, it works with how the urscript looks at moment.

A more robust solution might be to add a line to the urscript which makes it possible to distinguish between header and control loop. The current solution is searching for the "socket_open" line, which is the first line of code in the control loop.

Copy link
Collaborator

@fmauch fmauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think the idea is really good, but we should definitely tackle the generateScript problem mentioned.


while (it < splitData.length) {
// Find the first line of the control loop
if (splitData[it].startsWith(" socket_open(")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems absolutely brittle. As you mentioned in the OP, it might be better to define some anchors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the script has been moved to the client library issue I will define some anchors to search for.

@urmahp
Copy link
Contributor Author

urmahp commented Mar 10, 2021

I have added a PR in the ROS driver, where I define the header and control loop part in the control script. These changes are needed in order to be able to have multiple URCap nodes in one program.

@urrsk
Copy link
Member

urrsk commented Mar 17, 2021

@urmahp If the HEADER section is not defined, will it result in the similar behavior as before?
If, I will suggest that we suggest we merge it when ready.

@fmauch
Copy link
Collaborator

fmauch commented Mar 17, 2021

@urmahp If the HEADER section is not defined, will it result in the similar behavior as before?
If, I will suggest that we suggest we merge it when ready.

I think this comment has not been addressed, right?

@urmahp
Copy link
Contributor Author

urmahp commented Mar 17, 2021

@urmahp If the HEADER section is not defined, will it result in the similar behavior as before?
If, I will suggest that we suggest we merge it when ready.

Yes we should see same behavior as before the changes if the header is not defined.

I think this comment has not been addressed, right?

It has been addressed in commit efbdfb8. I moved the request part, so that the script is only requested if the URCap is part of the robot program.

@fmauch
Copy link
Collaborator

fmauch commented Mar 17, 2021

@urmahp If the HEADER section is not defined, will it result in the similar behavior as before?
If, I will suggest that we suggest we merge it when ready.

Yes we should see same behavior as before the changes if the header is not defined.

I think this comment has not been addressed, right?

It has been addressed in commit efbdfb8. I moved the request part, so that the script is only requested if the URCap is part of the robot program.

I'll give it another review then, later today / tonight

Copy link
Collaborator

@fmauch fmauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have minor suggestions for the documentation, otherwise it looks good. However, I didn't have time to properly test it, yet. Will do that tonight.

README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
@urmahp
Copy link
Contributor Author

urmahp commented Mar 17, 2021

I just have minor suggestions for the documentation, otherwise it looks good. However, I didn't have time to properly test it, yet. Will do that tonight.

Thanks for the review @fmauch.

I will update the documentation first thing tomorrow.

@fmauch
Copy link
Collaborator

fmauch commented Mar 17, 2021

I just have minor suggestions for the documentation, otherwise it looks good. However, I didn't have time to properly test it, yet. Will do that tonight.

Thanks for the review @fmauch.

I will update the documentation first thing tomorrow.

I would be fine with simply accepting my suggestions 😉

@urmahp
Copy link
Contributor Author

urmahp commented Mar 17, 2021

Could I just click commit suggestion to accept them?

@fmauch
Copy link
Collaborator

fmauch commented Mar 17, 2021

Could I just click commit suggestion to accept them?

Yes, indeed.

String[] programArray = program.split("\n");

for (int it = 0; it < programArray.length; ++it) {
if (programArray[it].matches("(.*)# HEADER_BEGIN(.*)")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing only whitespaces before and after might be safer. If people write comments like

# This does not go into the "# HEADER_BEGIN" section
Suggested change
if (programArray[it].matches("(.*)# HEADER_BEGIN(.*)")) {
if (programArray[it].matches("(\s*)# HEADER_BEGIN(\s*)")) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to brake the URCap when building, to make it build following if (programArray[it].matches("(\\s*)# HEADER_BEGIN(\\s*)")) will be needed.

When testing it with # This does not go into the "# HEADER_BEGIN" section the only time it seems to be able to find the # HEADER_BEGIN is with the original implementation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this post \\p{Zs} might be a working solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested \\p{Zs} and it recognizes # HEADER_BEGIN but not # This is a comment about # HEADER_BEGIN

@urmahp If you would be fine with this, I will push that to your branch and then we're ready to merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have also tested that it works and it seems like a good solution, thanks for you help.

@fmauch
Copy link
Collaborator

fmauch commented Mar 17, 2021

I've tested it and it seems to do its job perfectly!

@ipa-lth
Copy link
Contributor

ipa-lth commented Mar 18, 2021

Thx, for your approach!
I was desperatly trying to uncorrelate PRs on the urcap and the driver. This led to a too hacky proposal (which worked for my application, however), but never left WIP status.
Anyways, I am looking forward to rebase to an official release.
In general, I still feel like this is a (elegant) workaround for an urcap-API mishap.

@urrsk
Copy link
Member

urrsk commented Mar 18, 2021

@ipa-lth Thanks for your suggestion and sharing it, we are really grateful for that. It help pushing us in the right direction.

I agree that the control loop could be placed into a script function as well. Thus global variables have the disadvantage/feature that they will show up in the teach pendant's variable window.

The "share codes between the URCap nodes" is a general problem and the "workaround" should also work with other contexts than the ROS driver. See e.g. https://sdurobotics.gitlab.io/ur_rtde/examples/examples.html#use-with-externalcontrol-ur-cap

@ipa-lth
Copy link
Contributor

ipa-lth commented Mar 18, 2021

See e.g. https://sdurobotics.gitlab.io/ur_rtde/examples/examples.html#use-with-externalcontrol-ur-cap

Nice lib! Thanks for sharing.
This will be very interesting for those colleques trying to minimize ROS dependencies.

mahp and others added 3 commits March 21, 2021 23:14
The header is only appended to the UR program once, while the control loop is appended for each urcap node.

This enables the possibility to have multiple urcap nodes in one program.
Changed behavior so the program is only requested once the urcap is part of the program.
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 this pull request may close these issues.

4 participants