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

Firmware Training- Rukshi Thiyagayogan #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rukshi101
Copy link

No description provided.

Copy link
Collaborator

@Yehia-Fahmy Yehia-Fahmy left a comment

Choose a reason for hiding this comment

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

Hello I reviewed your servo code, so far you've done a good job usually it takes many reviews before code gets approved so don't be discouraged by the number of comments. If anything is unclear don't hesitate to reach out and ask. You can message me on the discord or reply to one of my comments.

using namespace std;


TutorialServo::TutorialServo(PinName servoPin, float servoRangeInDegrees = 180.0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of providing default values as you have done we do it by providing something called a member initializer list. Below is a link explaining what that means. Try implementing this in your code.

https://en.cppreference.com/w/cpp/language/constructor


#include "mbed.h"
#include "TutorialServo.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

The only thing you need to include is TutorialServo.h, also we dont normally use "using namespace std"

TutorialServo::TutorialServo(PinName servoPin, float servoRangeInDegrees = 180.0,
float minPulsewidthInMs = 1, float maxPulsewidthInMs = 2)
{
//declares this pin as pwm using pwmout.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Inside your constructor there doesn't need to be any code. Really in this application the only purpose of the constructor is to use the member initializer list to initialize the member variables of the object.

void TutorialServo::setPositionInDegrees(const float degrees)
{

m_servoRangeInDegrees = degrees;
Copy link
Collaborator

Choose a reason for hiding this comment

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

What you are doing here is changing the member variable, this isn't going to change the angle of the motor at all. What you want to do is to call the method of setting the pulsewidth on the servoPwmOut i.e including the following line of code instead:

m_servoPwmOut.pulsewidth_ms(some_argument);

Think about what should the argument for this function be and dont hesitate to hit me up on discord for more help.

float TutorialServo::getServoRangeInDegrees() const
{
return m_servoRangeInDegrees;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

looking good

float TutorialServo::getMaxPulseWidthInMs() const
{
return m_maxPulsewidthInMs;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

good stuff

@@ -0,0 +1,24 @@
#pragma once
Copy link
Collaborator

Choose a reason for hiding this comment

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

check your indenting on this file, depending on your code editor you can probably select a setting that can format your code every time you save. If that's not an option make sure you go through and manually indent.

Copy link
Member

Choose a reason for hiding this comment

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

There's a section in our repo readme called "Clang-Format" that walks you through setting up the formatter we use. Please go through it and use it to format the training files. Our formatting style uses an indentation of 2 spaces so you'll know you've formatted your file properly if the indentation is 2 spaces.
image

#include "TutorialServo.h"
#include "CANBus.h"
#include "CANMsg.h"
#include "mbed.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

For your include statements:

  • you dont need to include mbed.h (its already included in the header file)
  • make sure you include hw_bridge.h

}
}

TutorialServo servoObject;
Copy link
Collaborator

Choose a reason for hiding this comment

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

be careful because these lines of code will never be run (your code will enter the while loop and never leave)


int main()
{
CANBus can(CAN1_RX, CAN1_TX, HWBRIDGE::ROVERCONFIG::ROVER_CANBUS_FREQUENCY);
Copy link
Collaborator

Choose a reason for hiding this comment

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

these declarations are well done (since they are right at the top of your main function), make sure to declare your servo object as one of the first things you do

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