Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into V2
  • Loading branch information
NoozAbooz committed Jan 17, 2025
2 parents 27314d3 + 5990601 commit e8e0e9b
Show file tree
Hide file tree
Showing 19 changed files with 593 additions and 531 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
uses: actions/checkout@v3

- name: Build PROS Project
run: pros make clean all
run: make -j
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ INCDIR=$(ROOT)/include

WARNFLAGS+=
EXTRA_CFLAGS=
EXTRA_CXXFLAGS=
EXTRA_CXXFLAGS=-Wno-deprecated-enum-enum-conversion

# Set to 1 to enable hot/cold linking
USE_PACKAGE:=1
Expand Down
2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LIBRARIES+=$(wildcard $(FWDIR)/*.a)
EXCLUDE_COLD_LIBRARIES+=$(FWDIR)/libc.a $(FWDIR)/libm.a
COLD_LIBRARIES=$(filter-out $(EXCLUDE_COLD_LIBRARIES), $(LIBRARIES))
wlprefix=-Wl,$(subst $(SPACE),$(COMMA),$1)
LNK_FLAGS=--gc-sections --start-group $(strip $(LIBRARIES)) -lgcc -lstdc++ --end-group -T$(FWDIR)/v5-common.ld
LNK_FLAGS=--gc-sections --start-group $(strip $(LIBRARIES)) -lgcc -lstdc++ --end-group -T$(FWDIR)/v5-common.ld --no-warn-rwx-segments

ASMFLAGS=$(MFLAGS) $(WARNFLAGS)
CFLAGS=$(MFLAGS) $(CPPFLAGS) $(WARNFLAGS) $(GCCFLAGS) --std=$(C_STANDARD)
Expand Down
Binary file modified firmware/robodash.a
Binary file not shown.
3 changes: 1 addition & 2 deletions include/abstractGlobals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ extern rd_view_t *allianceview;
extern rd::Selector gui_selector;
void rdconfig_init();

extern bool isCompetition;
extern std::string alliance;
extern std::string auton_name;
extern std::string field_status;
extern void competitionTelemtryRefresh();

/* Functions */
// DT
Expand Down
16 changes: 8 additions & 8 deletions include/deviceGlobals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ inline pros::Controller controller(pros::E_CONTROLLER_MASTER);
// inline pros::MotorGroup rightDrive({-12, 13, -17});

// v1
inline pros::MotorGroup leftDrive({-1, -2, 3});
inline pros::MotorGroup rightDrive({6, -7, 8});
inline pros::MotorGroup leftDrive({-18, 19, 20});
inline pros::MotorGroup rightDrive({-11, 12, 13});

// Intake
inline pros::Motor intake(-10);
inline pros::Motor intake(-14);
inline pros::MotorGroup wallStake({-13, 14});

// Pneumatics
Expand All @@ -26,23 +26,23 @@ inline pros::adi::Pneumatics doinkerPiston('B', false);
inline pros::Optical optical(14);
inline pros::Imu inertial1(17);
inline pros::Imu inertial2(15);
inline pros::Rotation wallStakeSensor(12);
inline pros::Rotation wallStakeRotationSensor(12);

inline pros::Rotation verticalEncoder(4);
inline pros::Rotation horizontalEncoder(-5);
//hello world it is 210K secret note iykyk :D
// horizontal tracking wheel
inline lemlib::TrackingWheel vertical_tracking_wheel(&verticalEncoder, lemlib::Omniwheel::NEW_2, 0.44);
inline lemlib::TrackingWheel vertical_tracking_wheel(&verticalEncoder, lemlib::Omniwheel::NEW_275, 0.44);
// vertical tracking wheel
inline lemlib::TrackingWheel horizontal_tracking_wheel(&horizontalEncoder, lemlib::Omniwheel::NEW_2, 1.65);
inline lemlib::TrackingWheel horizontal_tracking_wheel(&horizontalEncoder, lemlib::Omniwheel::NEW_275, 1.65);

// drivetrain settings
inline lemlib::Drivetrain drivetrain(&leftDrive, // left motor group
&rightDrive, // right motor group
13.5, // track width
lemlib::Omniwheel::NEW_325,
360, // drivetrain rpm
2 // chase power is 2. If we had traction wheels, it would have been 8
450, // drivetrain rpm
8 // chase power is 2. If we had traction wheels, it would have been 8
);
// lateral motion controller
inline lemlib::ControllerSettings lateralController(10, // proportional gain (kP)
Expand Down
2 changes: 1 addition & 1 deletion include/libKS/drivetrain/odom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ks

extern Position odom_pos;

extern void odomThread();
extern void odomUpdate();
extern void setOdomPosition(double x_new, double y_new, double theta_new);
extern void initializeOdom();
extern pros::Task odom_task;
Expand Down
222 changes: 131 additions & 91 deletions include/libKS/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,139 @@
#include <numeric> // for std::accumulate
#include <algorithm>
#include <deque>
#include <cmath>

namespace ks
{
inline double vector_average(const std::vector<double>& v) {
return std::accumulate(v.begin(), v.end(), 0.0) / v.size();
}
inline double median_filter(std::deque<double>& buffer, double newVal, int windowSize) {
buffer.push_back(newVal);
if (buffer.size() > windowSize) {
buffer.pop_front();
}

std::vector<double> data(buffer.begin(), buffer.end());
std::sort(data.begin(), data.end());

return data[windowSize / 2];
}
// prolly dont use this 💀
inline double tripleIMUHeading(double heading1, double heading2, double heading3, double threshold) {
// Run through median filter
int windowSize = 20;
std::deque<double> buffer1;
std::deque<double> buffer2;
std::deque<double> buffer3;
heading1 = ks::median_filter(buffer1, heading1, windowSize);
heading2 = ks::median_filter(buffer2, heading2, windowSize);
heading3 = ks::median_filter(buffer3, heading3, windowSize);
// Calculate the absolute differences between the headings
double diff12 = std::abs(heading1 - heading2);
double diff23 = std::abs(heading2 - heading3);
double diff13 = std::abs(heading1 - heading3);
// Check if one of the sensors is drifting
if (diff12 > threshold && diff13 > threshold) {
// Sensor 1 is drifting, return mean of sensor 2 and 3
return (heading2 + heading3) / 2.0;
} else if (diff12 > threshold && diff23 > threshold) {
// Sensor 2 is drifting, return mean of sensor 1 and 3
return (heading1 + heading3) / 2.0;
} else if (diff23 > threshold && diff13 > threshold) {
// Sensor 3 is drifting, return mean of sensor 1 and 2
return (heading1 + heading2) / 2.0;
} else {
// No sensor is drifting, return mean of all sensors
// (or all of them are drifing and we just gotta pray 💀)
return (heading1 + heading2 + heading3) / 3.0;
}
}
inline bool isDriverControl() {
return pros::competition::is_connected() && !pros::competition::is_autonomous() && !pros::competition::is_disabled();
}
inline float reduce_0_to_360(float angle) {
while(!(angle >= 0 && angle < 360)) {
if( angle < 0 ) { angle += 360; }
if(angle >= 360) { angle -= 360; }
}
return(angle);
}
inline float reduce_negative_180_to_180(float angle) {
while(!(angle >= -180 && angle < 180)) {
if( angle < -180 ) { angle += 360; }
if(angle >= 180) { angle -= 360; }
}
return(angle);
}
inline float reduce_negative_90_to_90(float angle) {
while(!(angle >= -90 && angle < 90)) {
if( angle < -90 ) { angle += 180; }
if(angle >= 90) { angle -= 180; }
}
return(angle);
}
inline double to_rad(double angle_deg){
return(angle_deg/(180.0/M_PI));
}
inline double to_deg(double angle_rad){
return(angle_rad*(180.0/M_PI));
}
inline float clamp(float input, float min, float max){
if( input > max ){ return(max); }
if(input < min){ return(min); }
return(input);
}
inline bool isReversed(double input){
if(input<0) return(true);
return(false);
}
inline float to_milivolt(float input){
inline double vector_average(const std::vector<double>& v) {
return std::accumulate(v.begin(), v.end(), 0.0) / v.size();
}

inline double median_filter(std::deque<double>& buffer, double newVal, int windowSize) {
buffer.push_back(newVal);
if (buffer.size() > windowSize) {
buffer.pop_front();
}
std::vector<double> data(buffer.begin(), buffer.end());
std::sort(data.begin(), data.end());
return data[windowSize / 2];
}

// prolly dont use this 💀
inline double tripleIMUHeading(double heading1, double heading2, double heading3, double threshold) {
// Run through median filter
int windowSize = 20;
std::deque<double> buffer1;
std::deque<double> buffer2;
std::deque<double> buffer3;
heading1 = ks::median_filter(buffer1, heading1, windowSize);
heading2 = ks::median_filter(buffer2, heading2, windowSize);
heading3 = ks::median_filter(buffer3, heading3, windowSize);
// Calculate the absolute differences between the headings
double diff12 = std::abs(heading1 - heading2);
double diff23 = std::abs(heading2 - heading3);
double diff13 = std::abs(heading1 - heading3);
// Check if one of the sensors is drifting
if (diff12 > threshold && diff13 > threshold) {
// Sensor 1 is drifting, return mean of sensor 2 and 3
return (heading2 + heading3) / 2.0;
} else if (diff12 > threshold && diff23 > threshold) {
// Sensor 2 is drifting, return mean of sensor 1 and 3
return (heading1 + heading3) / 2.0;
} else if (diff23 > threshold && diff13 > threshold) {
// Sensor 3 is drifting, return mean of sensor 1 and 2
return (heading1 + heading2) / 2.0;
} else {
// No sensor is drifting, return mean of all sensors
// (or all of them are drifing and we just gotta pray 💀)
return (heading1 + heading2 + heading3) / 3.0;
}
}

inline bool isDriverControl() {
return pros::competition::is_connected() && !pros::competition::is_autonomous() && !pros::competition::is_disabled();
}

inline double reduce_0_to_360(double angle) {
while(!(angle >= 0 && angle < 360)) {
if( angle < 0 ) { angle += 360; }
if(angle >= 360) { angle -= 360; }
}
return(angle);
}

inline double reduce_negative_180_to_180(double angle) {
while(!(angle >= -180 && angle < 180)) {
if( angle < -180 ) { angle += 360; }
if(angle >= 180) { angle -= 360; }
}
return(angle);
}

inline double reduce_negative_90_to_90(double angle) {
while(!(angle >= -90 && angle < 90)) {
if( angle < -90 ) { angle += 180; }
if(angle >= 90) { angle -= 180; }
}
return(angle);
}

inline double to_rad(double angle_deg){
return(angle_deg/(180.0/M_PI));
}

inline double to_deg(double angle_rad){
return(angle_rad*(180.0/M_PI));
}

inline double clamp(double input, double min, double max){
if( input > max ){ return(max); }
if(input < min){ return(min); }
return(input);
}

inline bool isReversed(double input){
if(input<0) return(true);
return(false);
}

inline float to_milivolt(float input){
return(input * (12000.0/127.0));
}
inline float deadband(float input, float width){
if (fabs(input)<width){
return(0);
}
return(input);
}
}

class PID {
public:
// Constructor
PID(double kP, double kI, double kD)
: kP(kP),
kI(kI),
kD(kD) {}

// Member function to update PID
double update(const double error) {
// calculate integral
integral += error;

// calculate derivative
const double derivative = error - prevError;
prevError = error;

// calculate output
return error * kP + integral * kI + derivative * kD;
}

// Member function to reset PID
void reset() {
integral = 0;
prevError = 0;
}

protected:
// Member variables
double kP;
double kI;
double kD;
double integral = 0;
double prevError = 0;
};
}
4 changes: 2 additions & 2 deletions include/robodash/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#define ROBODASH
#define RD_VERSION_MAJOR 2
#define RD_VERSION_MINOR 1
#define RD_VERSION_PATCH 1
#define RD_VERSION_MINOR 2
#define RD_VERSION_PATCH 0

#include "liblvgl/lvgl.h"

Expand Down
8 changes: 8 additions & 0 deletions include/robodash/views/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class Image {
*/
Image(lv_img_dsc_t *image_dsc, std::string name = "Image");

/**
* @brief Create a new Image
*
* @param image_dsc Pointer to constant LVGL image descriptor object
* @param name Name to display on screen
*/
Image(const lv_img_dsc_t *image_dsc, std::string name = "Image");

/**
* @brief Set this view to the active view
*/
Expand Down
Loading

0 comments on commit e8e0e9b

Please sign in to comment.