Skip to content

Support setting parameters to unsigned intergers.#1759

Closed
zouyonghao wants to merge 1 commit intoros2:masterfrom
zouyonghao:master
Closed

Support setting parameters to unsigned intergers.#1759
zouyonghao wants to merge 1 commit intoros2:masterfrom
zouyonghao:master

Conversation

@zouyonghao
Copy link
Copy Markdown
Contributor

No description provided.

@fujitatomoya
Copy link
Copy Markdown
Collaborator

@zouyonghao thank you for posting PR and contribution ❗

is this related to #1743? could you describe a bit about what the actual problem is, i think it is better to discuss on what we are trying to fix as 1st.

best,

@zouyonghao
Copy link
Copy Markdown
Contributor Author

Hi @fujitatomoya , actually I didn't see #1743 before, I just want to use unsigned int for myself.
It seems this PR fix part of #1743 because currently I just add unsigned int and uint64_t support for now.

Signed-off-by: zouyonghao <yonghaoz1994@gmail.com>
@zouyonghao
Copy link
Copy Markdown
Contributor Author

Hi, @fujitatomoya .
I read #1743 again, I think this pr fix it for supporting uint32 and uint64.

@fujitatomoya
Copy link
Copy Markdown
Collaborator

I think this only fixes construction of ParameterValue, but i believe that there are other things to be considered.

i might be missing something else.

@zouyonghao
Copy link
Copy Markdown
Contributor Author

zouyonghao commented Aug 31, 2021

I agree with you @fujitatomoya .
This PR is just a simple fix for current parameter architecture.
If we want a more complete solution, we should redesign the rcl first.
For example, we can add type support for yaml parser with tags:

unsigned_parameter: !uint32 123

Copy link
Copy Markdown
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

Unfortunately this is by design, we do not want to ever be doing casting or truncating from unsigned to signed for the user. We would prefer instead to have the user cast the integer to an int64_t themselves, checking for these conditions and handling exceptional cases on their own.

So I would say this is a "won't fix". Sorry.

Comment on lines +151 to +153
if (int_value > INT32_MAX) {
throw std::runtime_error("Can not set a unsinged parameter to negitive value");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We intentionally did not support unsigned integers being assigned into the signed integer parameters in order to avoid checks like this.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Sep 21, 2021

If instead you wanted to introduce a new parameter type, where the storage is uint64_t then we could consider doing that, though we explicitly avoided that as we thought that int64_t would be sufficient for pretty much any use case as it could store anything that a uint32_t could anyway.

So there would need to be a compelling case for adding the unsigned type to the parameter system.

@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Sep 21, 2021

I'm going to close this as we don't want to include this feature, but please continue the conversation if you would like, and I can re-open the pull request if something changes during the discussion.

Thanks for opening the pull request to begin with!

@wjwwood wjwwood closed this Sep 21, 2021
@wjwwood
Copy link
Copy Markdown
Member

wjwwood commented Sep 21, 2021

Also, as I mentioned here:

#1743 (comment)

We might be able to support uint32_t explicitly as it could be assigned (I think) into an int64_t without any additional checks or failure cases (needs to be verified). Certainly for uint16_t and lower we could do it. But just unsigned int isn't a good type to take as it can vary in size.

@lucas-tiz
Copy link
Copy Markdown

Here's a concrete example: I'm currently trying to use an ODrive motor controller for a robotics application. Many of the parameters on the ODrive are either uint32 or uint64 so I cannot use ROS parameters to configure these?

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