I am trying to code my X - Drive base with voltage control… I’m not sure if I’m doing it right or wrong. These errors keep coming up, IDK what to do anymore.
#include "main.h"
// Helper Functions
// Driver Control Functions
void setDrive() {
int leftJoystickX = controller.get_analog (pros::E_CONTROLLER_ANALOG_X);
int leftJoystickY = controller.get_analog (pros::E_CONTROLLER_ANALOG_Y);
int rightJoystickX = controller.get_analog (pros::E_CONTROLLER_ANALOG_X);
int lateral = leftJoystickX(1, 4);
int linear = leftJoystickY(1, 3);
int rotation = rightJoystickX(1, 1);
// Y component, X component, Rotation
topLeftDrive.motorSet( -linear - lateral - rotation);
topRightDrive.motorSet( linear - lateral - rotation);
backLeftDrive.motorSet( linear + lateral - rotation);
backRightDrive.motorSet( -linear + lateral - rotation);
}
// Autonomous Functions
Here are the errors
you didnt initialize your motors or controller, so it has no idea what you are telling it to move and get values from.
so i have to re-define them in initalize.cpp?
#include "main.h"
// MOTORS
extern pros::Motor frontLeftDrive;
extern pros::Motor frontRightDrive;
extern pros::Motor backLeftDrive;
extern pros::Motor backRightDrive;
//CONTROLLER
extern pros::Controller controller;
//MICS
I have this in my globals.hpp file and this in my globals.cpp file
#include "main.h"
// Motors
pros::Motor topLeftDrive(1, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS );
pros::Motor topRightDrive(2, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS );
pros::Motor backLeftDrive(3, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS );
pros::Motor backRightDrive(4, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS );
// Controller
pros::Controller controller(pros::E_CONTROLLER_MASTER);
the header file is included in main.h
sorry I rushed my first reply and didn’t notice that you were using multiple .cpp files. comparing your code to my own I can’t find any actual errors, the only thing that I can think of is in the screenshot you provided none of your files are saved. This would cause your globals to not be updated to your current code. if saving doesn’t fix it the best thing I can recommend is to create a new project and then to rewrite/copy your code into it.
3 Likes
If you compile your program, are there errors?
I get a bin/(hot or cold) package error
Im gonna try creating a new PROS project becuase I dont believe that I did anything wrong
The errors are still there…
The compiler errors say otherwise…
Your globals.hpp is wrong. You put the motors as the wrong name.
3 Likes
I renamed them to make sure, I posted the .hpp file before the .cpp file. That was before the change. That is not the problem. Im aware the compiler says otherwise.
I fixed it, thanks for the help guys.
Just curious what was the issue?
me being dumb and over complicating things
this is what I finished with
// Drivercontrol Functions
int lateral ;
int linear ;
int rotation ;
void setDrive() {
lateral = controller.get_analog (pros::E_CONTROLLER_ANALOG_LEFT_X);
linear = controller.get_analog (pros::E_CONTROLLER_ANALOG_LEFT_Y);
rotation = controller.get_analog (pros::E_CONTROLLER_ANALOG_RIGHT_X);
// Y component, X component, Rotation
topLeftDrive = ( -linear - lateral - rotation);
topRightDrive = ( linear - lateral - rotation);
backLeftDrive = ( linear + lateral - rotation);
backRightDrive = ( -linear + lateral - rotation);
}
// Autonomous Functions
I did pros::E_CONTROLLER_ANALOG_X
instead of pros::E_CONTROLLER_ANALOG_LEFT_X
4 Likes