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

Feature/publish encoder data #334

Open
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

PilzES
Copy link
Contributor

@PilzES PilzES commented Aug 16, 2022

Description

These changes Fix # | allow the user to | improve | ...


PR Checklist

Things to add, update or check by the maintainers before this PR can be merged.

  • Public api function documentation
  • Architecture documentation reflects actual code structure
  • Tutorials
  • Overview on ROS wiki
  • Package Readme (example pilz_robots)
  • Good commit messages (some tips)
  • CHANGELOG.rst updated
  • Copyright headers
  • Examples

Review Checklist

  • Soft- and hardware architecture (diagrams and description)
  • Test review (test plan and individual test cases)
  • Documentation describes purpose of file(s) and responsibilities
  • Code (coding rules, style guide)

Release planning (please answer)

  • When is the new feature released?
  • Which dependent packages do have to be released simultaneously?

Hardware tests

Unstrike the text below to enable automatic hardware tests if available. Otherwise use this as a request for the reviewer.

  • Perform hardware tests

Copy link
Contributor

@martiniil martiniil left a comment

Choose a reason for hiding this comment

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

Review part 1 (28/39 files viewed)...

include/psen_scan_v2/encoder_state_ros_conversion.h Outdated Show resolved Hide resolved
include/psen_scan_v2/ros_scanner_node.h Show resolved Hide resolved
include/psen_scan_v2/ros_scanner_node.h Outdated Show resolved Hide resolved
launch/psen_scan_v2.launch Outdated Show resolved Hide resolved
Comment on lines 170 to 178
uint16_t encoder_1_read_buffer;
raw_processing::read<uint16_t>(ss, encoder_1_read_buffer);

uint16_t encoder_2_read_buffer;
raw_processing::read<uint16_t>(ss, encoder_2_read_buffer);

encoder::EncoderData encoder_data;
encoder_data.encoder_1 = toEncoder(encoder_1_read_buffer);
encoder_data.encoder_2 = toEncoder(encoder_2_read_buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving those lines to a small function deserializeEncoderData(), analoguous to IOs/diagnostics.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just read in the protocol that the encoder values are sent in reversed byte order (big endian). If I am correct then we have to further convert the values (swap the bytes like e.g. https://stackoverflow.com/questions/3823921/convert-big-endian-to-little-endian-when-reading-from-a-binary-file/3824338#3824338)

Copy link
Contributor Author

@PilzES PilzES Nov 15, 2022

Choose a reason for hiding this comment

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

Many thanks for the great example, I believe I hit it. Check it carefully and let me know your opinion. See 842f074

standalone/src/encoder_state.cpp Show resolved Hide resolved
@@ -148,6 +149,7 @@ ScannerConfiguration ScannerAPITests::generateScannerConfig(const std::string& h
.scanRange(DEFAULT_SCAN_RANGE)
.scanResolution(DEFAULT_SCAN_RESOLUTION)
.enableIntensities()
.enableEncoder(ENCODER_ENABLED)
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to include the encoder states in the ScanDataEqual matcher in matcher_and_actions.h else they are ignored by the integrationtest_scanner_api tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved. Code modified to add the encoder states at ScanDataEqual. See commit 55257b0

Copy link
Contributor

@martiniil martiniil left a comment

Choose a reason for hiding this comment

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

Review part 2

I hope you do not get overwhelmed by my comments. Most of them are minor things.

  • Currently one test is failing: MonitoringFrameDeserializationTest.shouldDeserializeMonitoringFrameCorrectly. In order to make it work we have to extend WithIntensitiesAndDiagnostics in udp_frame_dumps.h with encoder data.
  • We should also enable the encoders in the test crcWithIntensities in unittest_start_request.cpp, where we need then to find out the new expected_crc via wireshark.

Comment on lines 170 to 178
uint16_t encoder_1_read_buffer;
raw_processing::read<uint16_t>(ss, encoder_1_read_buffer);

uint16_t encoder_2_read_buffer;
raw_processing::read<uint16_t>(ss, encoder_2_read_buffer);

encoder::EncoderData encoder_data;
encoder_data.encoder_1 = toEncoder(encoder_1_read_buffer);
encoder_data.encoder_2 = toEncoder(encoder_2_read_buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

I just read in the protocol that the encoder values are sent in reversed byte order (big endian). If I am correct then we have to further convert the values (swap the bytes like e.g. https://stackoverflow.com/questions/3823921/convert-big-endian-to-little-endian-when-reading-from-a-binary-file/3824338#3824338)

Comment on lines 109 to 113
uint16_t encoder_1_payload = static_cast<uint16_t>(msg.encoderData().encoder_1);
raw_processing::write(os, encoder_1_payload);

uint16_t encoder_2_payload = static_cast<uint16_t>(msg.encoderData().encoder_2);
raw_processing::write(os, encoder_2_payload);
Copy link
Contributor

Choose a reason for hiding this comment

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

Above comment about the byte order also applies here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as #334 (comment). See 842f074

standalone/include/psen_scan_v2_standalone/encoder_state.h Outdated Show resolved Hide resolved
standalone/test/unit_tests/api/unittest_laserscan.cpp Outdated Show resolved Hide resolved

EXPECT_NO_THROW(psen_scan_v2::EncoderState ros_message = toEncoderStateMsg(encoder_state, "some_frame"));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tests for:

  • the ros_message header is set correctly
  • the encoder_* fields are set correctly
  • an exception is thrown if the supplied time is negative

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The requested three tests added

PilzES and others added 20 commits November 11, 2022 11:37
I agree.

Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
…er/encoder_data.h

Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
…er/encoder_data.h

Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
…on.cpp

Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
…er/monitoring_frame_deserialization.h

Co-authored-by: Immanuel Martini <35950815+martiniil@users.noreply.github.com>
Comment on lines 124 to 128
inline void endswap(T *objp)
{
unsigned char *memp = reinterpret_cast<unsigned char*>(objp);
std::reverse(memp, memp + sizeof(T));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Using a reference instead of a pointer would align better with the rest of the code. Of course you need to change the invocations, too. E.g. raw_processing::endswap(&encoder_1_read_buffer) gets raw_processing::endswap(encoder_1_read_buffer)
  • We don't abbreviate the names that much, but that is only a suggestion
Suggested change
inline void endswap(T *objp)
{
unsigned char *memp = reinterpret_cast<unsigned char*>(objp);
std::reverse(memp, memp + sizeof(T));
}
inline void endianSwap(T& data)
{
unsigned char *dataPtr = reinterpret_cast<unsigned char*>(&data);
std::reverse(dataPtr, dataPtr + sizeof(T));
}

Choose a reason for hiding this comment

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

Agree totally, modified and commited in 6f7cfba

@PilzES PilzES marked this pull request as ready for review December 7, 2022 12:38
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.

3 participants