44#include " units/Vector2D.hpp"
55#include " units/Vector3D.hpp"
66
7- /* *
8- * A callback function for LLEMU's center button.
9- *
10- * When this callback is fired, it will toggle line 2 of the LCD text between
11- * "I was pressed!" and nothing.
12- */
13- void on_center_button () {
14- static bool pressed = false ;
15- pressed = !pressed;
16- if (pressed) {
17- pros::lcd::set_text (2 , " I was pressed!" );
18- } else {
19- pros::lcd::clear_line (2 );
20- }
21- }
7+ constexpr int r2i (double value) { return static_cast <int >(value >= 0.0 ? value + 0.5 : value - 0.5 ); }
228
239/* *
2410 * Runs initialization code. This occurs as soon as the program is started.
@@ -27,9 +13,6 @@ void on_center_button() {
2713 * to keep execution time for this mode under a few seconds.
2814 */
2915void initialize () {
30- pros::lcd::initialize ();
31- pros::lcd::set_text (1 , " Hello PROS User!" );
32- pros::lcd::register_btn1_cb (on_center_button);
3316 units::AccelerationPose a (1_mps2, 2_mps2);
3417 Number num = Number (1.0 );
3518 num = Number (0.0 );
@@ -38,9 +21,6 @@ void initialize() {
3821 std::ratio<0 >, std::ratio<0 >>(1.0 );
3922 a.orientation += 2_rpm2;
4023 2_rpm2 -= a.orientation ;
41- to_cDeg (Quantity<std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<1 >, std::ratio<0 >,
42- std::ratio<0 >, std::ratio<0 >>(5.0 ) -
43- a.theta () + 5_cDeg);
4424 Quantity<std::ratio<0 >, std::ratio<0 >, std::ratio<1 >, std::ratio<0 >, std::ratio<1 >, std::ratio<0 >, std::ratio<0 >,
4525 std::ratio<0 >>
4626 c = Multiplied<Angle, Time>();
@@ -49,9 +29,6 @@ void initialize() {
4929 Length z = toLinear<Angle>(y, 2_cm);
5030 static_assert (Angle (5.1 ) >= Quantity<std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<1 >,
5131 std::ratio<0 >, std::ratio<0 >, std::ratio<0 >>(5.0 ));
52- units::clamp (2_cDeg, a.theta (),
53- Quantity<std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<1 >, std::ratio<0 >,
54- std::ratio<0 >, std::ratio<0 >>(5.0 ));
5532 units::max (10_celsius, Quantity<std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<0 >, std::ratio<0 >,
5633 std::ratio<1 >, std::ratio<0 >, std::ratio<0 >>(1.0 ));
5734 // check Vector3D overloads
@@ -68,66 +45,10 @@ void initialize() {
6845 units::Vector2D<Number> v2e = units::V2Position (2_in, 2_in) / 2_in;
6946}
7047
71- /* *
72- * Runs while the Probot is in the disabled state of Field Management System or
73- * the VEX Competition Switch, following either autonomous or opcontrol. When
74- * the robot is enabled, this task will exit.
75- */
76- void disabled () {}
77-
78- /* *
79- * Runs after initialize(), and before autonomous when connected to the Field
80- * Management System or the VEX Competition Switch. This is intended for
81- * competition-specific initialization routines, such as an autonomous selector
82- * on the LCD.
83- *
84- * This task will exit when the robot is enabled and autonomous or opcontrol
85- * starts.
86- */
87- void competition_initialize () {}
88-
89- /* *
90- * Runs the user autonomous code. This function will be started in its own task
91- * with the default priority and stack size whenever the robot is enabled via
92- * the Field Management System or the VEX Competition Switch in the autonomous
93- * mode. Alternatively, this function may be called in initialize or opcontrol
94- * for non-competition testing purposes.
95- *
96- * If the robot is disabled or communications is lost, the autonomous task
97- * will be stopped. Re-enabling the robot will restart the task, not re-start it
98- * from where it left off.
99- */
100- void autonomous () {}
101-
102- /* *
103- * Runs the operator control code. This function will be started in its own task
104- * with the default priority and stack size whenever the robot is enabled via
105- * the Field Management System or the VEX Competition Switch in the operator
106- * control mode.
107- *
108- * If no competition control is connected, this function will run immediately
109- * following initialize().
110- *
111- * If the robot is disabled or communications is lost, the
112- * operator control task will be stopped. Re-enabling the robot will restart the
113- * task, not resume it from where it left off.
114- */
115- void opcontrol () {
116- pros::Controller master (pros::E_CONTROLLER_MASTER);
117- pros::MotorGroup left_mg ({1 , -2 , 3 }); // Creates a motor group with forwards ports 1 & 3 and reversed port 2
118- pros::MotorGroup right_mg ({-4 , 5 , -6 }); // Creates a motor group with forwards port 4 and reversed ports 4 & 6
119-
120- while (true ) {
121- pros::lcd::print (0 , " %d %d %d" , (pros::lcd::read_buttons () & LCD_BTN_LEFT) >> 2 ,
122- (pros::lcd::read_buttons () & LCD_BTN_CENTER) >> 1 ,
123-
124- (pros::lcd::read_buttons () & LCD_BTN_RIGHT) >> 0 ); // Prints status of the emulated screen LCDs
125-
126- // Arcade control scheme
127- int dir = master.get_analog (ANALOG_LEFT_Y); // Gets amount forward/backward from left joystick
128- int turn = master.get_analog (ANALOG_RIGHT_X); // Gets the turn left/right from right joystick
129- left_mg.move (dir - turn); // Sets left motor voltage
130- right_mg.move (dir + turn); // Sets right motor voltage
131- pros::delay (20 ); // Run for 20 ms then update
132- }
48+ void angleTests () {
49+ static_assert (+15_cDeg == 75_stDeg);
50+ static_assert (to_stDeg (-+15_cDeg) == to_stDeg (105_stDeg));
51+ static_assert (r2i (to_stDeg (30_cDeg)) == r2i (to_stDeg (60_stDeg)));
52+ static_assert (r2i (to_stDeg (+0_cDeg)) == r2i (to_stDeg (90_stDeg)));
53+ Angle a = 2_cDeg;
13354}
0 commit comments