-
Notifications
You must be signed in to change notification settings - Fork 337
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
Less copy paste #88
Less copy paste #88
Conversation
1) making getters const 2) less error prone unpacking with template specialization 3) use safer std::unique_lock when possible
Nice code, I just wrote similar functions two weeks ago: https://github.com/NikolasE/ur_modern_driver/commit/13dc20e8549e1d149a8e8529598005e710ecc7ed (double parseDouble...) :) |
Honestly I didn't check if float works. I just know that my code is SUPPOSED to do what the prvioud code does. |
By the way. It is nice to see that more people feel that a similar solution would be clearer. This in my (humble) opinion is safer and less error prone, because otherwise no one prevent you to use parseDouble on a variable that is supposed to be an int. I guess it is a subjective decision. I noticed also that you had problems as well with formatting, which makes your commit more "dirty". We should start using automated formatting as I suggested in #89 |
I tested your float-function and it fails for my UR10 with CB3. tool_voltage_48V: 3458792192.0 |
does the original code (master) work? I will double check during the weekend o spot what is different |
it did not work for me. The other parsing functions are working, but not the float |
sorry, I am not sure I understood. Are you confirming that the float parsing is wrong as well in the master branch? The double version (that works), can be re-written as void RobotState::unpackVariable<double>(const uint8_t *buffer, unsigned int& offset, double& dest){
uint64_t temp;
memcpy(&temp, &buffer[offset], sizeof(temp));
offset += sizeof(temp);
temp = be64toh(temp);
memcpy(&dest, &temp, sizeof(dest));
} Therefore I assume that the correct implementation for float would be void RobotState::unpackVariable<float>(const uint8_t *buffer, unsigned int& offset, float& dest){
uint32_t temp;
memcpy(&temp, &buffer[offset], sizeof(temp));
offset += sizeof(temp);
temp = be32toh(temp);
memcpy(&dest, &temp, sizeof(dest));
} I can not use the robot today. Can you test it? If you can't, I will check this out on Monday |
By the way, I will move these methods to free standing functions in another file, since they can be reused to parse robot_state_RT.cpp too. |
I started with the functions I extracted from the master and did not get useful values for the floats. I just ran your code (with the be32toh) and got this output: rostopic echo /ur_driver/tool_data analog_input_range2: 1 (tool_data is only available in my fork I think) The tool current and temperature are correct, (no idea what the tool_voltage_48V means and I'm not sure about the uchar-value of 205 for the output_voltage). So I think this float-function is correct. |
Is there anything that prevent us from merging this PR? |
Hi,
I would like to propose these changes which remove several lines of copied and pasted (and error prone) code.
Note that I haven't had the opportunity to test it yet, but I want to start discussing if you agree from a "philosophical" point of view with these changes ;)
Merge may come once we broadly tested this on the actual robot.
Davide