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

✨Field Control State Getter #608

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

#define PROS_VERSION_MAJOR 4
#define PROS_VERSION_MINOR 0
#define PROS_VERSION_PATCH 2
#define PROS_VERSION_STRING "4.0.2"
#define PROS_VERSION_PATCH 5
#define PROS_VERSION_STRING "4.0.5"

#include "pros/adi.h"
#include "pros/colors.h"
Expand Down
12 changes: 12 additions & 0 deletions include/pros/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define COMPETITION_DISABLED (1 << 0)
#define COMPETITION_AUTONOMOUS (1 << 1)
#define COMPETITION_CONNECTED (1 << 2)
#define COMPETITION_SYSTEM (1 << 3)
Copy link
Member

Choose a reason for hiding this comment

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

since we're making breaking changes anyways, do we want to switch this into an enum instead? If it's a readability thing with bits we could also just add a comment or support both enums and the old macros.


#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -130,6 +131,17 @@ uint8_t competition_get_status(void);
*/
#define competition_is_autonomous() ((competition_get_status() & COMPETITION_AUTONOMOUS) != 0)

/**
* \return True if the V5 Brain is connected to VEXnet Field Controller, false otherwise.
*/
#define competition_is_field_control() ((competition_get_status() & COMPETITION_SYSTEM) != 0)
Copy link
Member

Choose a reason for hiding this comment

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

ditto on the macro thing... maybe these could be functions?


/**
* \return True if the V5 Brain is connected to VEXnet Competition Switch, false otherwise.
*/
#define competition_is_competition_switch() ((competition_get_status() & COMPETITION_SYSTEM) == 0)
Copy link
Member

Choose a reason for hiding this comment

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

we should come up with a better naming scheme for these, I know it's a legacy thing but man competition_is_competition is kind of repetitive.



///@}

/// \name V5 Controller
Expand Down
2 changes: 2 additions & 0 deletions include/pros/misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ std::uint8_t get_status(void);
std::uint8_t is_autonomous(void);
std::uint8_t is_connected(void);
std::uint8_t is_disabled(void);
bool is_field_control(void);
bool is_competition_switch(void);
} // namespace competition

namespace usd {
Expand Down
9 changes: 9 additions & 0 deletions src/devices/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,14 @@ std::uint8_t is_connected(void) {
std::uint8_t is_disabled(void) {
return competition_is_disabled();
}

bool is_field_control(void) {
return competition_is_field_control();
}

bool is_competition_switch(void) {
return competition_is_competition_switch();
}

} // namespace competition
} // namespace pros
22 changes: 21 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,25 @@ void competition_initialize() {}
* will be stopped. Re-enabling the robot will restart the task, not re-start it
* from where it left off.
*/
void autonomous() {}
void autonomous() {
while (1) {
if (pros::competition::is_field_control()) {
printf("[Auton] testing is_field_control(): true\n");
}
else {
printf("[Auton] testing is_field_control(): false\n");
}

if (pros::competition::is_competition_switch()) {
printf("[Auton] testing is_competition_switch(): true\n");
}
else {
printf("[Auton] testing is_competition_switch(): false\n");
}

pros::delay(1000);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

be sure to remove this before merge.


/**
* Runs the operator control code. This function will be started in its own task
Expand All @@ -79,8 +97,10 @@ void opcontrol() {
pros::MotorGroup right_mg({-4,5,-6}); // Creates a motor group with forwards port 4 and reversed ports 4 & 6

while (true) {

pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,
(pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,

(pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0); // Prints status of the emulated screen LCDs

// Arcade control scheme
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.2
4.0.5
Copy link
Member

Choose a reason for hiding this comment

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

forgot the newline... somebody did somewhere earlier as well. Please add it back