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

SNS: Serial Communication #120

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

SNS: Serial Communication #120

wants to merge 11 commits into from

Conversation

kshxtij
Copy link
Contributor

@kshxtij kshxtij commented Mar 3, 2022

Description

Implements UART communication with the Arduino to receive structs containing wheel encoder data.

Implemented

  • Updated Arduino Code
  • Serial Interface in hyped::utils::io

@codecov-commenter
Copy link

codecov-commenter commented Mar 3, 2022

Codecov Report

Merging #120 (e5baf90) into master (728a673) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #120   +/-   ##
=======================================
  Coverage   33.95%   33.95%           
=======================================
  Files          67       67           
  Lines        3549     3549           
=======================================
  Hits         1205     1205           
  Misses       2344     2344           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 728a673...e5baf90. Read the comment docs.

@kshxtij kshxtij changed the title Serial Communication SNS: Serial Communication Mar 3, 2022
@kshxtij kshxtij self-assigned this Mar 3, 2022
Copy link
Member

@mifrandir mifrandir left a comment

Choose a reason for hiding this comment

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

Even if you hadn't violated every single rule in our style guide, I would still be advising you to rewrite all of this. I'm not sure this is good C code, but it's definitely not good C++.

You are using malloc, plenty of raw pointers, int as file descriptors, and many other things that don't have a place here. To solve the problem in question, I advise you to have a look at the following:

src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.hpp Outdated Show resolved Hide resolved
src/utils/io/serial.hpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.hpp Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
arduino/main.ino Show resolved Hide resolved
arduino/main.ino Show resolved Hide resolved
// The payload that will be sent to the other device
struct Payload {
int16_t wheelEncoderA;
int16_t wheelEncoderB;
Copy link
Member

Choose a reason for hiding this comment

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

wheel_encoder_a

src/utils/io/serial.hpp Outdated Show resolved Hide resolved
src/utils/io/serial.hpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved
src/utils/io/serial.cpp Outdated Show resolved Hide resolved

void SerialProtocol::configureTermios()
{
serial_ = open(serial_device_.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
Copy link
Contributor

@arjunnaha arjunnaha Apr 7, 2022

Choose a reason for hiding this comment

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

I think some of these lines need comments as the constant names are not obvious (e.g. O_NOCTTY)


struct termios options;
tcgetattr(serial_, &options);
options.c_cflag = CS8 | CLOCAL | CREAD;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

src/utils/io/serial.hpp Show resolved Hide resolved
#include <StreamSerialProtocol.h>
#include <ArduinoSerialProtocol.h>

int IRSensor1 = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems brittle if we add/remove the number of IR sensors and wheel encoders? Can we not maintain a map of IR sensors and wheel encoders and loop through?

Copy link
Member

@mifrandir mifrandir Apr 9, 2022

Choose a reason for hiding this comment

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

I disagree. We are only ever going to have four IR sensors. Let's not make it more complicated than it needs to be.

Looking at it again, we should not be using a map, I stand by that. However, I don't see why we don't have something like

#define kNumWheelEncoders 4
const int kWheelEncoders[kNumWheelEncoders] = { /* ... */};

Sorry, I was thinking in terms of C++.

Of course, this also raises the question of how we are going to do testing when we require all four to be present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants