Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 4b6f1fb

Browse files
authored
Merge pull request #75 from calhighrobotics/improvements/issue-72/skills-auton
Added some skills fixes for competition field
2 parents 555e311 + 7faba9e commit 4b6f1fb

File tree

10 files changed

+691
-274
lines changed

10 files changed

+691
-274
lines changed

include/globals.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ extern pros::Rotation lateral_sensor;
7575
extern pros::Rotation horizontal_sensor;
7676

7777
extern pros::Rotation LadyBrownRotation;
78+
extern pros::Rotation HookRotation;
79+
7880

7981
// forward/backward PID
8082
extern lemlib::ControllerSettings lateral_controller;
@@ -92,11 +94,15 @@ extern lemlib::ExpoDriveCurve throttle_curve;
9294

9395
extern lemlib::ExpoDriveCurve steer_curve;
9496

97+
extern lemlib::ExpoDriveCurve arcade_turn_curve;
98+
9599
extern pros::adi::DigitalIn drivetrainToggleSwitch;
96100
extern pros::adi::DigitalIn autonToggleSwitch;
97101

98102
extern pros::adi::Pneumatics LatchControl;
99103
extern pros::adi::Pneumatics SweeperControl;
104+
extern pros::adi::Pneumatics IntakeLift;
105+
extern pros::adi::DigitalIn HookSwitch;
100106

101107
} // namespace Globals
102108
} // namespace Robot

include/robot/auton.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Autonomous {
6464
* strategy. It contains the specific actions and movements required for this
6565
* strategy.
6666
*/
67-
void RedNeg(Intake &intake, Latch &latch, DistanceSensor &distance);
67+
void RedNeg(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown);
6868

6969
/**
7070
* @brief Runs the autonomous path for the near side offensive game strategy.
@@ -102,7 +102,7 @@ class Autonomous {
102102
* @todo Make the autonomous more fleshed out, building it properly for the
103103
* competition
104104
*/
105-
void BlueNeg(Intake &intake, Latch &latch, DistanceSensor &distance);
105+
void BlueNeg(Intake &intake, Latch &latch, DistanceSensor &distance, LadyBrown &ladybrown);
106106

107107
/**
108108
* Executes the Skills challenge autonomous.

include/robot/ladybrown.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Robot {
99
class LadyBrown {
1010
public:
1111
// The ENUM associates with each location of the rotation sensor for the LadyBrown to move.
12-
enum LADYBROWN_STATE { BASE_STATE = 1, LOAD_STATE = 2, ATTACK_STATE = 3 };
12+
enum LADYBROWN_STATE { BASE_STATE = 1, LOAD_STATE = 2, ATTACK_STATE = 3, SIZECHECK_STATE = 4 };
1313

1414
void run(bool async = true, int timeout = 1000);
1515

@@ -22,10 +22,16 @@ class LadyBrown {
2222
private:
2323
lemlib::PID MoveToPointPID;
2424

25+
lemlib::PID ActiveBrakePID;
26+
27+
int brake_target;
28+
2529
static LADYBROWN_STATE current_state;
2630

2731
int target;
2832

2933
bool isPIDRunning;
34+
35+
bool manualControl;
3036
};
3137
} // namespace Robot

src/globals.cpp

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "globals.h"
22
#include "pros/abstract_motor.hpp"
3+
#include "pros/adi.hpp"
34
#include "pros/misc.hpp"
45
#include "pros/motors.hpp"
56
#include "pros/optical.hpp"
67
#include "pros/vision.h"
7-
#include "pros/vision.hpp"
88

99
/*
1010
* Although the following constants belong in their own seperate
@@ -23,29 +23,35 @@ namespace Globals {
2323
pros::Controller controller(pros::E_CONTROLLER_MASTER);
2424
pros::Controller partner(pros::E_CONTROLLER_PARTNER);
2525

26-
pros::Motor RightFront(13, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
27-
pros::Motor LeftFront(-19, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
28-
pros::Motor LeftBack(-18, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
29-
pros::Motor RightBack(12, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
30-
pros::Motor LeftMid(20, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
31-
pros::Motor RightMid(-11, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
32-
pros::Motor IntakeMotor(-9, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
33-
pros::Motor HookMotor(7, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
34-
pros::Motor LadyBrownMotor(-3, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
26+
pros::Motor RightFront(16, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
27+
pros::Motor LeftFront(-13, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
28+
pros::Motor LeftBack(-11, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
29+
pros::Motor RightBack(14, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
30+
pros::Motor LeftMid(12, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
31+
pros::Motor RightMid(-15, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
32+
pros::Motor IntakeMotor(-4, pros::v5::MotorGears::blue, pros::v5::MotorUnits::degrees);
33+
pros::Motor HookMotor(3, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
34+
pros::Motor LadyBrownMotor(-10, pros::v5::MotorGears::green, pros::v5::MotorUnits::degrees);
3535

3636
pros::adi::Pneumatics LatchControl('A', false);
3737
pros::adi::Pneumatics SweeperControl('B', false);
38+
pros::adi::Pneumatics IntakeLift('D', false);
3839

39-
pros::Distance distance_sensor(10);
40-
pros::Rotation lateral_sensor(16);
41-
pros::Rotation horizontal_sensor(17);
40+
pros::adi::DigitalIn HookSwitch('C');
4241

43-
pros::Rotation LadyBrownRotation(8);
4442

45-
pros::Imu inertial_sensor(15);
43+
pros::Distance distance_sensor(6);
44+
pros::Rotation lateral_sensor(-19);
45+
pros::Rotation horizontal_sensor(-20);
46+
47+
pros::Rotation LadyBrownRotation(9);
48+
pros::Rotation HookRotation(2);
49+
50+
51+
pros::Imu inertial_sensor(17);
4652

4753
// Vision sensor configuration
48-
pros::Optical colorSensor(4);
54+
pros::Optical colorSensor(5);
4955

5056
pros::vision_signature_s_t RED_SIG =
5157
pros::c::vision_signature_from_utility(1, -4653, -3619, -4136, 9831, 11725, 10778, 2.5, 0);
@@ -62,15 +68,15 @@ pros::MotorGroup drive_({LeftFront.get_port(), RightFront.get_port(), LeftMid.ge
6268
LeftBack.get_port(), RightBack.get_port()});
6369

6470
// Lemlib objects - Used by lemlib drive and odometry functions
65-
lemlib::TrackingWheel horizontal_tracking_wheel(&horizontal_sensor, 2, -2.75);
66-
lemlib::TrackingWheel vertical_tracking_wheel(&lateral_sensor, 2, -1);
71+
lemlib::TrackingWheel horizontal_tracking_wheel(&horizontal_sensor, 2, 0.25);
72+
lemlib::TrackingWheel vertical_tracking_wheel(&lateral_sensor, 2, -0.625);
6773

6874
// Describes the lemlib objects that are used to control the autonomous
6975
// functions of the robot.
7076
lemlib::Drivetrain drivetrain{
7177
&drive_left, // left drivetrain motors
7278
&drive_right, // right drivetrain motors
73-
12.25, // track width
79+
10.8, // track width
7480
lemlib::Omniwheel::OLD_325,
7581
450, // drivetrain rpm is 450
7682
2 // horizontal drift is 2
@@ -86,38 +92,56 @@ lemlib::OdomSensors sensors{
8692

8793
// forward/backward PID
8894
// lateral PID controller
89-
lemlib::ControllerSettings lateral_controller(6.5, // proportional gain (kP)
95+
lemlib::ControllerSettings lateral_controller(6.4, // proportional gain (kP)
9096
0, // integral gain (kI)
9197
35, // derivative gain (kD)
92-
0, // anti windup
98+
3, // anti windup
9399
0.5, // small error range, in inches
94100
100, // small error range timeout, in milliseconds
95-
3, // large error range, in inches
101+
2, // large error range, in inches
96102
500, // large error range timeout, in milliseconds
97-
20 // maximum acceleration (slew)
103+
115 // maximum acceleration (slew)
98104
);
99105

100-
// angular PID controller
101-
lemlib::ControllerSettings angular_controller(2.1, // proportional gain (kP)
106+
// 0, // anti windup
107+
// 0.5, // small error range, in inches
108+
// 100, // small error range timeout, in milliseconds
109+
// 3, // large error range, in inches
110+
// 500, // large error range timeout, in milliseconds
111+
// 20
112+
113+
// angular PID controller 2.2 17 Last test: kp 13 kd 75, kp was just before full oscilation, kd was just before jittering
114+
lemlib::ControllerSettings angular_controller(3.27, // proportional gain (kP)
102115
0, // integral gain (kI)
103-
14, // derivative gain (kD)
104-
0, // anti windup
105-
0.5, // small error range, in degrees
106-
100, // small error range timeout, in milliseconds
107-
2, // large error range, in degrees
116+
27.5, // derivative gain (kD)
117+
3, // anti windup
118+
2, // small error range, in degrees
119+
90, // small error range timeout, in milliseconds
120+
3, // large error range, in degrees
108121
500, // large error range timeout, in milliseconds
109-
0 // maximum acceleration (slew)
122+
0 // maximum acceleration (slew)
110123
);
111124

112-
lemlib::ExpoDriveCurve throttle_curve(3, // joystick deadband out of 127
113-
50, // minimum output where drivetrain will move out of 127
114-
0.992 // expo curve gain
125+
// 2, // small error range, in degrees
126+
// 80, // small error range timeout, in milliseconds
127+
// 3, // large error range, in degrees
128+
// 500, // large error range timeout, in milliseconds
129+
// 0
130+
131+
lemlib::ExpoDriveCurve throttle_curve(1, // joystick deadband out of 127
132+
35, // minimum output where drivetrain will move out of 127
133+
1.002 // expo curve gain
115134
);
116135

117136
// input curve for steer input during driver control
118-
lemlib::ExpoDriveCurve steer_curve(3, // joystick deadband out of 127
119-
17, // minimum output where drivetrain will move out of 127
120-
1 // expo curve gain
137+
lemlib::ExpoDriveCurve steer_curve(1, // joystick deadband out of 127
138+
16, // minimum output where drivetrain will move out of 127
139+
1.0084 // expo curve gain
140+
);
141+
142+
lemlib::ExpoDriveCurve arcade_turn_curve(1, // joystick deadband out of 127
143+
8, // minimum output where drivetrain will move out of 127
144+
1.016 // expo curve gain
121145
);
122146

123147
lemlib::Chassis chassis(drivetrain, lateral_controller, angular_controller, sensors, &throttle_curve, &steer_curve);

src/main.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "lemlib/chassis/chassis.hpp"
66
#include "liblvgl/llemu.hpp"
77
#include "pros/misc.h"
8+
#include "lemlib/timer.hpp"
89
#include "pros/misc.hpp"
910
#include "pros/motors.hpp"
1011
#include "pros/rtos.hpp"
@@ -78,11 +79,19 @@ void initialize() {
7879
// delay to save resources
7980
pros::lcd::print(3, "Lateral Sensor: %i", lateral_sensor.get_position());
8081
pros::lcd::print(4, "Horizontal Sensor: %i", horizontal_sensor.get_position());
81-
pros::lcd::print(5, "Lady Brown Sensor: %i", LadyBrownRotation.get_position());
82+
pros::lcd::print(5, "Lady Brown Sensor: %i", HookMotor.get_voltage());
8283
pros::lcd::print(6, "Autonomous: %s", subsystem.autonomous.autonName);
83-
pros::lcd::print(7, "Distance Position: %i", distance_sensor.get_distance());
84+
pros::lcd::print(7, "Distance Position: %i", HookRotation.get_position());
8485

85-
pros::delay(20);
86+
double total_wattage = LeftBack.get_power() + RightBack.get_power() + LeftFront.get_power() +
87+
RightFront.get_power() + LeftMid.get_power() + RightMid.get_power() +
88+
IntakeMotor.get_power() + HookMotor.get_power() + LadyBrownMotor.get_power();
89+
90+
//std::cout << "Total Wattage: " << total_wattage << std::endl;
91+
//std::cout << chassis.getPose().theta << std::endl;
92+
//std::cout << chassis.getPose().x << ", " << chassis.getPose().y << std::endl;
93+
94+
pros::delay(100);
8695
}
8796
});
8897

@@ -138,7 +147,7 @@ void disabled() {}
138147
* starts.<asd></asd>
139148
*/
140149
void competition_initialize() {
141-
screen.selector.selector();
150+
//screen.selector.selector();
142151

143152
}
144153

@@ -155,11 +164,15 @@ void competition_initialize() {
155164
*/
156165

157166
void autonomous() {
158-
Autonomous::auton = Autonomous::BLUE_POS_LATE_RUSH;
167+
Autonomous::auton = Autonomous::BLUE_NEG;
159168
subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch, subsystem.sweeper, electronic.distance_sensor,
160-
subsystem.ladybrown);
161-
}
169+
subsystem.ladybrown);
170+
171+
// chassis.setPose(0, 0, 0);
172+
// chassis.moveToPoint(0, -3.5, 1000, {.forwards = false});
162173

174+
175+
}
163176
/**
164177
* Runs the operator control code. This function will be started in its own
165178
* task with the default priority and stack size whenever the robot is enabled
@@ -177,34 +190,18 @@ void opcontrol() {
177190

178191
while (true) {
179192

180-
// Calls to event handling functions.
181-
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_UP)) {
182-
autonomous();
183-
}
184193
// Toggles the drivetrain orientation - can be forward or backward
185-
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_RIGHT)) {
194+
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_LEFT)) {
186195
std::string name = subsystem.drivetrain.toggleDrive();
187196
// Output the current drive mode to the controller screen
188197
controller.print(0, 0, name.c_str());
189198
}
190-
// Checks for drivetrain reversal - Changes conditions in a value handler function in the drivetrain class
191-
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_DOWN)) {
192-
// isReversed is static, it is changed for the global state.
193-
Drivetrain::isReversed = !Drivetrain::isReversed;
194-
195-
// Output the current drive mode to the controller screen
196-
controller.print(0, 0, "reversal: %d", Drivetrain::isReversed);
197-
}
198-
199-
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) {
200-
pros::Task move([&]() { subsystem.ladybrown.MoveToPoint(LadyBrown::ATTACK_STATE); }, "LadyBrownMove");
201-
}
202199

203200
if (controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_X)) {
204-
IntakeMotor.move_velocity(600);
201+
pros::Task move([&]() { subsystem.ladybrown.MoveToPoint(LadyBrown::ATTACK_STATE); }, "LadyBrownMove");
205202
}
206203

207-
204+
208205

209206
subsystem.drivetrain.run();
210207
subsystem.latch.run();

0 commit comments

Comments
 (0)