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

Commit acfd590

Browse files
aswsubJay9971
andauthored
feat (Distance Sensor): Distance Sensor class w/ Autonomous interop (#66)
Co-authored-by: Jay9971 <robertmasked@gmail.com>
1 parent 803e892 commit acfd590

File tree

8 files changed

+51
-22
lines changed

8 files changed

+51
-22
lines changed

include/electronic/distance.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
namespace Robot {
4+
5+
class DistanceSensor {
6+
public:
7+
8+
9+
DistanceSensor();
10+
11+
int get_distance();
12+
13+
};
14+
}

include/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern pros::vision_signature_s_t RED_SIG;
6868
extern pros::vision_signature_s_t BLUE_SIG;
6969
extern pros::vision_signature_s_t BLUE_DARK_SIG;
7070

71+
extern pros::Distance distance_sensor;
7172
extern pros::Rotation lateral_sensor;
7273
extern pros::Rotation horizontal_sensor;
7374
// forward/backward PID

include/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "api.h"
3838
#include "electronic/controller.h"
39+
#include "electronic/distance.h"
3940
#include "globals.h"
4041
#include "pros/apix.h"
4142
#include "robot/auton.h"

include/robot/auton.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "robot/intake.h"
55
#include "robot/latch.h"
6+
#include "electronic/distance.h"
67

78
namespace Robot {
89
/**
@@ -41,7 +42,7 @@ class Autonomous {
4142
* @param puncher A reference to the Puncher object.
4243
* @param autono A boolean value indicating whether to use autonomous mode.
4344
*/
44-
void AutoDrive(Intake &intake, Latch &latch);
45+
void AutoDrive(Intake &intake, Latch &latch, DistanceSensor &distance);
4546

4647
/**
4748
* @brief Switches the autonomous program.
@@ -61,7 +62,7 @@ class Autonomous {
6162
* strategy. It contains the specific actions and movements required for this
6263
* strategy.
6364
*/
64-
void Auton1(Intake &intake, Latch &latch);
65+
void Auton1(Intake &intake, Latch &latch, DistanceSensor &distance);
6566

6667
/**
6768
* @brief Runs the autonomous path for the near side offensive game strategy.
@@ -70,7 +71,7 @@ class Autonomous {
7071
* strategy. It contains the specific actions and movements required for this
7172
* strategy.
7273
*/
73-
void Auton2(Intake &intake, Latch &latch);
74+
void Auton2(Intake &intake, Latch &latch, DistanceSensor &distance);
7475

7576
/**
7677
* @brief Runs the puncher routine for the Skills Challenge.
@@ -81,7 +82,7 @@ class Autonomous {
8182
*
8283
* @param puncher A reference to the Puncher object.
8384
*/
84-
void Auton3(Intake &intake, Latch &latch);
85+
void Auton3(Intake &intake, Latch &latch, DistanceSensor &distance);
8586

8687
/**
8788
* @brief Runs the autonomous path for the far side offensive game strategy.
@@ -91,7 +92,7 @@ class Autonomous {
9192
* @todo Make the autonomous more fleshed out, building it properly for the
9293
* competition
9394
*/
94-
void Auton4(Intake &intake, Latch &latch);
95+
void Auton4(Intake &intake, Latch &latch, DistanceSensor &distance);
9596

9697
/**
9798
* Executes the Skills challenge autonomous.
@@ -102,6 +103,6 @@ class Autonomous {
102103
* @param intake The reference to the `Intake` object.
103104
* @param latch The reference to the `Latch` object.
104105
*/
105-
void Auton5(Intake &intake, Latch &latch);
106+
void Auton5(Intake &intake, Latch &latch, DistanceSensor &distance);
106107
};
107108
} // namespace Robot

src/electronics/distance.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "globals.h"
2+
#include "pros/misc.h"
3+
#include "electronic/distance.h"
4+
5+
using namespace Robot;
6+
using namespace Robot::Globals;
7+
8+
9+
DistanceSensor::DistanceSensor() { ; }
10+
11+
int DistanceSensor::get_distance() {
12+
return distance_sensor.get();
13+
}

src/globals.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ pros::adi::Pneumatics LatchControl('A', false);
3636
pros::adi::Pneumatics HangControl('C', false);
3737
pros::adi::Pneumatics SweeperControl('B', false);
3838

39+
40+
pros::Distance distance_sensor(10);
3941
pros::Rotation lateral_sensor(16);
4042
pros::Rotation horizontal_sensor(17);
4143

src/main.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct RobotScreen {
4444

4545
struct Electronics {
4646
Robot::Controller controllers;
47+
Robot::DistanceSensor distance_sensor;
4748
} electronic;
4849

4950
/**
@@ -123,11 +124,7 @@ void autonomous() {
123124
// }
124125
// });
125126

126-
subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch);
127-
128-
// chassis.turnToHeading(90, 100000);
129-
// chassis.turnToHeading(180, 2000);
130-
// chassis.moveToPoint(0, 24, 10000);
127+
subsystem.autonomous.AutoDrive(subsystem.intake, subsystem.latch, electronic.distance_sensor);
131128
}
132129

133130
/**

src/routines/auton.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,43 @@ Autonomous::AUTON_ROUTINE Autonomous::auton = RED_LEFT;
88
std::string Autonomous::autonName;
99

1010
// Red Left
11-
void Autonomous::Auton1(Intake &intake, Latch &latch) {}
11+
void Autonomous::Auton1(Intake &intake, Latch &latch, DistanceSensor &distance) {}
1212

1313
// Red Right
14-
void Autonomous::Auton2(Intake &intake, Latch &latch) {}
14+
void Autonomous::Auton2(Intake &intake, Latch &latch, DistanceSensor &distance) {}
1515

1616
// Blue left
17-
void Autonomous::Auton3(Intake &intake, Latch &latch) {}
17+
void Autonomous::Auton3(Intake &intake, Latch &latch, DistanceSensor &distance) {}
1818

1919
/*
2020
* @todo Flesh out this method before the competition in order to make it a full
2121
* solo awp autonomous. Blue right
2222
*/
23-
void Autonomous::Auton4(Intake &intake, Latch &latch) {}
23+
void Autonomous::Auton4(Intake &intake, Latch &latch, DistanceSensor &distance) {}
2424

25-
void Autonomous::Auton5(Intake &intake, Latch &latch) {
25+
void Autonomous::Auton5(Intake &intake, Latch &latch, DistanceSensor &distance) {
2626
// Autonomous routine for the Skills challenge
2727
}
2828

2929
// Takes in two parameters: The autonomous value as well as the puncher object.
30-
void Autonomous::AutoDrive(Intake &intake, Latch &latch) {
30+
void Autonomous::AutoDrive(Intake &intake, Latch &latch, DistanceSensor &distance) {
3131
// Keep the switcher running while the controller down button has not been pressed and the time period is not
3232
// autonomous Compare the current auton value to run the auton routine
3333
switch (Autonomous::auton) {
3434
case RED_LEFT:
35-
Auton1(intake, latch);
35+
Auton1(intake, latch, distance);
3636
break;
3737
case RED_RIGHT:
38-
Auton2(intake, latch);
38+
Auton2(intake, latch, distance);
3939
break;
4040
case BLUE_LEFT:
41-
Auton3(intake, latch);
41+
Auton3(intake, latch, distance);
4242
break;
4343
case BLUE_RIGHT:
44-
Auton4(intake, latch);
44+
Auton4(intake, latch, distance);
4545
break;
4646
case SKILLS:
47-
Auton5(intake, latch);
47+
Auton5(intake, latch, distance);
4848
break;
4949
}
5050
}

0 commit comments

Comments
 (0)