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

Swerve final #13

Open
wants to merge 77 commits into
base: dev
Choose a base branch
from
Open

Swerve final #13

wants to merge 77 commits into from

Conversation

ishanm0
Copy link
Contributor

@ishanm0 ishanm0 commented Jul 23, 2024

(I'm gonna use this to make comments)

bleubirb and others added 30 commits August 21, 2023 14:19
Co-authored-by: brendanRose1 <[email protected]>
Co-authored-by: ananya-manduva <[email protected]>
… fast (only in the negative direction though)

Co-authored-by: inkyant <[email protected]>
Converted Pi control of motors in python (motor test) to Pico control of motors in c (cooler motor test)
Co-authored-by: brendanRose1 <[email protected]>
Co-authored-by: ananya-manduva <[email protected]>
ishanm0 and others added 25 commits February 23, 2024 03:33
file cleanup
-new finalized branch for swerve module
-consolidates code into one folder
-try to make code match software map
-rewrite i2c-controller into separate classes
-remove old files & branches
unfinished 4 am code, hopefully a step forward?
i forgot to commit this, i think it finalizes changes
-still need to add integral windup correction
small tweaks to software structure, added small TODO notes
changes made with meeting with Ishan on ~5/16/24
moved everything into a new top-level folder to keep consistent with rest of repo
added basic-swerve dev folders
Added message library that encodes/decodes messages in specified format for modbot in c & python
Added processing for specific message ids in compute_module_id.py and swerve-module-id.h

Added decoding of payload of 24 bytes -> 6 floats, changes state of robot to read converted floats
moved old swerve-decoder folder into _OLD
Added top level code that might get the swerve drive working (with enough editing to everything else...)
restructured order of PID loop, libraries, etc (add readme of changes)
Copy link
Contributor Author

@ishanm0 ishanm0 left a comment

Choose a reason for hiding this comment

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

btw @brendanRose1 does this compile?

@@ -0,0 +1,36 @@

#include "pid.cpp"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

you should never include .c or .cpp files, instead, you use header files. in this case, you'd want to put the class definition with just the function signatures (ex. void Setup();) in a file called control-library.h, then in the corresponding cpp file, you define each function like this:

SwerveDrive::Setup() {
    //code
}

and so on, not organized/indented into a class structure. If you want an example, look at this .h file paired with this .cpp file

#include <stdio.h>
#include <stdlib.h>

#include "motor-library.cpp"
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 .h/.cpp comments from control-library.cpp

@@ -0,0 +1,198 @@
#include <stdio.h>

#include "motor-library.cpp"
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 .h/.cpp comments from motor-library.cpp for all of these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also, since all of your libraries are cpp code, your main file needs to be cpp as well, not c

*
* @return calculated checksum
*/
char MessagingBSDChecksum(char* payloadString, unsigned char payloadLen) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok so everything above this line is fine, but actual code in the function definition (everything between the curly braces) should be in the cpp file

STATE_ZERO_MOTORS
};

float resultArray[resultArraySize] = {0};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

iirc you can't do stuff like this (assigning variables) in a header file but I could be wrong

* @returns success/failure to process payload, next state of main state machine
*/
char MessagingProcessPayload(char* payload, unsigned char id, unsigned char len){
switch(id){
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 thing as messaging-library.h - the function code should be defined in a cpp file, not an h file

#define COUNT_MAX 65535

// class to instantiate swerve module
class PWMControl {
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 cpp/h organization comments as control-library.cpp

/**
* Motor class that holds PWMControl and quadrature_encoder class, encapsulates functions to set and read values of 1 motor
*/
class Motor{
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 cpp/h organization comments as control-library.cpp

const float PULLEY_RATIO = 0.3185 / 1.528;
const float DEG_PER_ROT = 360.0;

class Encoder
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 cpp/h organization comments

#include <pico/i2c_slave.h>
#include <pico/stdlib.h>

class ZeroingSensor{
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 cpp/h organization comments

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.

6 participants