Hello everyone,
I’m trying to learn PROS C++, but for some reason this very basic program only runs the motor on the first port. Even when there is no motor programmed to be spun in port 1, it still spins. I have checked and the other motors work fine out of program, they aren’t burnt out.
Here is the code:
#include "main.h"
/**
* A callback function for LLEMU's center button.
*
* When this callback is fired, it will toggle line 2 of the LCD text between
* "I was pressed!" and nothing.
*/
void on_center_button() {
static bool pressed = false;
pressed = !pressed;
if (pressed) {
pros::lcd::set_text(2, "wow");
} else {
pros::lcd::clear_line(2);
}
}
/**
* Runs initialization code. This occurs as soon as the program is started.
*
* All other competition modes are blocked by initialize; it is recommended
* to keep ex\ecution time for this mode under a few seconds.
*/
void initialize() {
pros::lcd::initialize();
pros::lcd::set_text(1, "Hello PROS User!");
pros::lcd::register_btn1_cb(on_center_button);
}
/**
* Runs while the robot is in the disabled state of Field Management System or
* the VEX Competition Switch, following either autonomous or opcontrol. When
* the robot is enabled, this task will exit.
*/
void disabled() {}
/**
* Runs after initialize(), and before autonomous when connected to the Field
* Management System or the VEX Competition Switch. This is intended for
* competition-specific initialization routines, such as an autonomous selector
* on the LCD.
*
* This task will exit when the robot is enabled and autonomous or opcontrol
* starts.
*/
void competition_initialize() {}
/**
* Runs the user autonomous code. This function will be started in its own task
* with the default priority and stack size whenever the robot is enabled via
* the Field Management System or the VEX Competition Switch in the autonomous
* mode. Alternatively, this function may be called in initialize or opcontrol
* for non-competition testing purposes.
*
* If the robot is disabled or communications is lost, the autonomous task
* will be stopped. Re-enabling the robot will restart the task, not re-start it
* from where it left off.
*/
void autonomous() {}
/**
* Runs the operator control code. This function will be started in its own task
* with the default priority and stack size whenever the robot is enabled via
* the Field Management System or the VEX Competition Switch in the operator
* control mode.
*
* If no competition control is connected, this function will run immediately
* following initialize().
*
* If the robot is disabled or communications is lost, the
* operator control task will be stopped. Re-enabling the robot will restart the
* task, not resume it from where it left off.
*/
void opcontrol() {
pros::Controller master(pros::E_CONTROLLER_MASTER);
pros::Motor leftFront(1);
pros::Motor rightFront(2);
pros::Motor leftBack(4);
pros::Motor rightBack(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);
int leftFront = master.get_analog(ANALOG_LEFT_Y);
int rightFront = master.get_analog(ANALOG_RIGHT_Y);
int leftBack = master.get_analog(ANALOG_LEFT_Y);
int rightBack = master.get_analog(ANALOG_RIGHT_Y);
leftFront = leftFront;
rightFront = rightFront;
leftBack = leftBack;
rightBack = rightBack;
pros::delay(20);
}
}
Then go on to set your motors equal to either right or left joystick respectively. You also may need to reverse some of the motors in the declaration (look up the documentation for that on the pros site).
Well, you’ve gotta start narrowing down the possible issues. Try using the printf function to print what left/right drive is supposed to be into the pros terminal, try swapping motors/motor ports, ext. There are so many different ways where things can go wrong you’ve got to verify what parts of your code/hardware are working as intended.
Note: Unofficial Response @CSpencer Honestly, there isn’t anything wrong with a little bit of handholding when someone is stumped, but by saying “figure it out” you’re just going to lock @Omnom up.
@Omnom Looking at your modified code (not the topic post, but your second post), I feel like it should work properly. Just to verify that this is not a PROS issue…
I would like to ask you some questions so I have awareness of what is going on:
Your code seems to be configured for tank drive. Is your intentions tank drive, where you push the left thumbstick forward to operate the left side of the robot and you push the right thumbstick forward to operate the right side of the robot?
I feel like this may be a problem unrelated to PROS. Could you check that all of the motors are plugged in correctly and firmly, and that all of the motors are lighting up red without any blinking?
If all motors are lighting up red without any blinking, could you test that every motor can spin via the Devices menu on the V5 screen?
Using your pros code, could you ensure that operator control function is properly being ran? Could you try connecting the robot to a field control or control switch and running that way?
I have come to the same conclusion but have tried many wires and motors and it still does not work, except with port 1.
Yes, I have tested the motors through the brain menu.
I will do that… as soon as I find one.
Also, just to let you know I have been told to go back to our old program (v5 text)… so its not a huge emergency to get this program running. But it would be nice to know why this doesn’t work.