-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
463 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.vscode | ||
/bin | ||
/build | ||
compile_commands.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"title":"Ri3D 2024","description":"Empty V5 C++ Project","icon":"USER921x.bmp","version":"23.09.1216","sdk":"20220726_10_00_00","language":"cpp","competition":false,"files":[{"name":"include/robot-config.h","type":"File","specialType":"device_config"},{"name":"include/vex.h","type":"File","specialType":""},{"name":"include/joystick.cpp","type":"File","specialType":""},{"name":"makefile","type":"File","specialType":""},{"name":"src/main.cpp","type":"File","specialType":""},{"name":"src/robot-config.cpp","type":"File","specialType":"device_config"},{"name":"vex/mkenv.mk","type":"File","specialType":""},{"name":"vex/mkrules.mk","type":"File","specialType":""},{"name":"include","type":"Directory"},{"name":"src","type":"Directory"},{"name":"vex","type":"Directory"}],"device":{"slot":1,"uid":"276-4810","options":{}},"isVexFileImport":false,"robotconfig":[]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "vex.h" | ||
#include <cmath> | ||
|
||
|
||
/* | ||
this class was made by Cole Huffine class of 2024 | ||
lets hope rivera gives this to future classes bc | ||
i think it would be useful for everyone | ||
*/ | ||
|
||
/* | ||
In order to use this class, put it in your "include" folder | ||
and then put '#inlcude "joystick.cpp"' at the top of your main file | ||
Usage: | ||
If you need to get the value of a joystick fixed to account for the physical limitations | ||
getLeftX(); | ||
getLeftY(); | ||
getRightX(); | ||
getRightY(); | ||
If you need to get the REAL value of a joystick, as inputted into the brain | ||
getTrueLeftX(); | ||
getTrueLeftY(); | ||
getTrueRightX(); | ||
getTrueRightY(); | ||
*/ | ||
|
||
/* | ||
If you want to use a second controller, or name your controller something else other than Controller1, | ||
then go to all of the getTrue methods, and change the name to what you have as your config | ||
*/ | ||
|
||
|
||
//this returns the sign of the value you pass in as a parameter | ||
//i originally made this file in java, and c++ doesnt have this | ||
//built in so i made it :) | ||
int signum(double val) { | ||
return (val >= 0) ? 1 : -1; | ||
} | ||
|
||
|
||
//use these if you need to get the true value of any joystick | ||
double getTrueLeftX() { | ||
return Controller1.Axis4.position(pct); | ||
} | ||
|
||
double getTrueLeftY() { | ||
return Controller1.Axis3.position(pct); | ||
} | ||
|
||
double getTrueRightX() { | ||
return Controller1.Axis1.position(pct); | ||
} | ||
|
||
double getTrueRightY() { | ||
return Controller1.Axis2.position(pct); | ||
} | ||
|
||
/* | ||
* This method is to fix the flawed input of a vex controller. The input is a box, | ||
* both X and Y axis can go from -1 to 1. However, since the controller build physically | ||
* forces the joystick into a circle, its impossible to reach the the corner of the box. | ||
* This method fixes that issue. | ||
*/ | ||
double joystickFix(bool isLeft, bool isX) { | ||
double root2 = sqrt(2); | ||
double x = isLeft ? getTrueLeftX() : getTrueRightX(); | ||
double y = isLeft ? getTrueLeftY() : getTrueRightY(); | ||
double magnitude = sqrt(x*x + y*y); | ||
double values[2] = { | ||
signum(x) * fmin(fabs(x*root2), magnitude), | ||
signum(y) * fmin(fabs(y*root2), magnitude) | ||
}; | ||
return isX? values[0] : values[1]; | ||
} | ||
|
||
|
||
// these return the fixed value of all of the joysticks | ||
double getLeftX() { | ||
return joystickFix(true, true); | ||
} | ||
|
||
double getLeftY() { | ||
return joystickFix(true, false); | ||
} | ||
|
||
double getRightX() { | ||
return joystickFix(false, true); | ||
} | ||
|
||
double getRightY() { | ||
return joystickFix(false, false); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using namespace vex; | ||
|
||
extern brain Brain; | ||
|
||
// VEXcode devices | ||
|
||
/** | ||
* Used to initialize code/tasks/devices added using tools in VEXcode Pro. | ||
* | ||
* This should be called at the start of your int main function. | ||
*/ | ||
void vexcodeInit( void ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*----------------------------------------------------------------------------*/ | ||
/* */ | ||
/* Module: vex.h */ | ||
/* Author: Vex Robotics */ | ||
/* Created: 1 Feb 2019 */ | ||
/* Description: Default header for V5 projects */ | ||
/* */ | ||
/*----------------------------------------------------------------------------*/ | ||
// | ||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "v5.h" | ||
#include "v5_vcs.h" | ||
|
||
#include "robot-config.h" | ||
|
||
#define waitUntil(condition) \ | ||
do { \ | ||
wait(5, msec); \ | ||
} while (!(condition)) | ||
|
||
#define repeat(iterations) \ | ||
for (int iterator = 0; iterator < iterations; iterator++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# VEXcode makefile 2019_03_26_01 | ||
|
||
# show compiler output | ||
VERBOSE = 0 | ||
|
||
# include toolchain options | ||
include vex/mkenv.mk | ||
|
||
# location of the project source cpp and c files | ||
SRC_C = $(wildcard src/*.cpp) | ||
SRC_C += $(wildcard src/*.c) | ||
SRC_C += $(wildcard src/*/*.cpp) | ||
SRC_C += $(wildcard src/*/*.c) | ||
|
||
OBJ = $(addprefix $(BUILD)/, $(addsuffix .o, $(basename $(SRC_C))) ) | ||
|
||
# location of include files that c and cpp files depend on | ||
SRC_H = $(wildcard include/*.h) | ||
|
||
# additional dependancies | ||
SRC_A = makefile | ||
|
||
# project header file locations | ||
INC_F = include | ||
|
||
# build targets | ||
all: $(BUILD)/$(PROJECT).bin | ||
|
||
# include build rules | ||
include vex/mkrules.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/*----------------------------------------------------------------------------*/ | ||
/* */ | ||
/* Module: main.cpp */ | ||
/* Author: C:\Users\User */ | ||
/* Created: Wed Mar 27 2024 */ | ||
/* Description: V5 project */ | ||
/* */ | ||
/*----------------------------------------------------------------------------*/ | ||
|
||
// ---- START VEXCODE CONFIGURED DEVICES ---- | ||
// Robot Configuration: | ||
// [Name] [Type] [Port(s)] | ||
// ---- END VEXCODE CONFIGURED DEVICES ---- | ||
|
||
#include "vex.h" | ||
#include <cmath> | ||
#include "joystick.cpp" | ||
|
||
using namespace vex; | ||
|
||
competition Competition; | ||
|
||
motor LeftDriveMotor = motor(1, ratio18_1, false); | ||
motor RightDriveMotor = motor(2, ratio18_1, false); | ||
motor FrontDriveMotor = motor(3, ratio18_1, false); | ||
motor BackDriveMotor = motor(4, ratio18_1, false); | ||
inertial Inertial = inertial(5); | ||
motor arm = motor(7, ratio36_1, false); | ||
motor deploy = motor(8, ratio18_1, false); | ||
motor climbMotorA = motor(9, ratio18_1, false); | ||
motor climbMotorB = motor(10, ratio18_1, true); | ||
motor_group climb = motor_group(climbMotorA, climbMotorB); | ||
controller Controller1 = controller(primary); | ||
|
||
|
||
class Drives { | ||
public: | ||
void static robotOirented() { | ||
double yInput = getLeftY(); | ||
double xInput = getLeftX(); | ||
double turning = getTrueRightX(); | ||
double leftMotor = yInput + turning; | ||
double rightMotor = yInput - turning; | ||
double frontMotor = xInput + turning; | ||
double backMotor = xInput - turning; | ||
|
||
LeftDriveMotor.spin(fwd, leftMotor, velocityUnits::pct); | ||
RightDriveMotor.spin(fwd, rightMotor, velocityUnits::pct); | ||
FrontDriveMotor.spin(fwd, frontMotor, velocityUnits::pct); | ||
BackDriveMotor.spin(fwd, backMotor, velocityUnits::pct); | ||
} | ||
|
||
void static autonDrive(double xIn, double yIn, double turnIn) { | ||
double yInput = yIn; | ||
double xInput = xIn; | ||
double turning = turnIn; | ||
double leftMotor = yInput + turning; | ||
double rightMotor = yInput - turning; | ||
double frontMotor = xInput + turning; | ||
double backMotor = xInput - turning; | ||
|
||
LeftDriveMotor.spin(fwd, leftMotor, velocityUnits::pct); | ||
RightDriveMotor.spin(fwd, rightMotor, velocityUnits::pct); | ||
FrontDriveMotor.spin(fwd, frontMotor, velocityUnits::pct); | ||
BackDriveMotor.spin(fwd, backMotor, velocityUnits::pct); | ||
} | ||
|
||
void static fieldOriented() { | ||
double headingRadians = Inertial.heading() * 3.141592/180; | ||
double yInput = getLeftY(); | ||
double xInput = getLeftX(); | ||
double sineHeading = sin(headingRadians); | ||
double cosHeading = cos(headingRadians); | ||
double rotatedYInput = xInput * sineHeading + yInput * cosHeading; | ||
double rotatedXInput = xInput * cosHeading - yInput * sineHeading; | ||
double turning = getTrueRightX(); | ||
double leftMotor = rotatedYInput + turning; | ||
double rightMotor = -rotatedYInput + turning; | ||
double FrontMotor = rotatedXInput + turning; | ||
double backMotor = -rotatedXInput + turning; | ||
|
||
LeftDriveMotor.spin(fwd, leftMotor, velocityUnits::pct); | ||
RightDriveMotor.spin(fwd, rightMotor, velocityUnits::pct); | ||
FrontDriveMotor.spin(fwd, FrontMotor, velocityUnits::pct); | ||
BackDriveMotor.spin(fwd, backMotor, velocityUnits::pct); | ||
} | ||
}; | ||
|
||
void pre_auton(void) { | ||
Inertial.setHeading(0.0, degrees); | ||
Inertial.setRotation(0.0, degrees); | ||
Inertial.startCalibration(); | ||
while(Inertial.isCalibrating()) { | ||
task::sleep(10); | ||
} | ||
Inertial.setHeading(0.0, degrees); | ||
Inertial.setRotation(0.0, degrees); | ||
|
||
// Initializing Robot Configuration. DO NOT REMOVE! | ||
vexcodeInit(); | ||
} | ||
|
||
void usercontrol(void) { | ||
while(true) { | ||
Drives::fieldOriented(); | ||
|
||
//zeroes inertial sensor | ||
if(Controller1.ButtonY.pressing()) { | ||
Inertial.setHeading(0.0, degrees); | ||
Inertial.setRotation(0.0, degrees); | ||
Inertial.startCalibration(); | ||
while (Inertial.isCalibrating()) { | ||
task::sleep(10); | ||
} | ||
Inertial.setHeading(0.0, degrees); | ||
Inertial.setRotation(0.0, degrees); | ||
} | ||
|
||
} | ||
} | ||
|
||
void auton(void) { | ||
Drives::autonDrive(0.0, 0.5, 0); | ||
task::sleep(4000); | ||
Drives::autonDrive(0.0, 0.0, 0); | ||
} | ||
|
||
int main() { | ||
pre_auton(); | ||
|
||
Competition.autonomous(auton); | ||
Competition.drivercontrol(usercontrol); | ||
|
||
while(true) { | ||
task::sleep(10); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "vex.h" | ||
|
||
using namespace vex; | ||
using signature = vision::signature; | ||
using code = vision::code; | ||
|
||
// A global instance of brain used for printing to the V5 Brain screen | ||
brain Brain; | ||
|
||
// VEXcode device constructors | ||
|
||
// VEXcode generated functions | ||
|
||
|
||
|
||
/** | ||
* Used to initialize code/tasks/devices added using tools in VEXcode Pro. | ||
* | ||
* This should be called at the start of your int main function. | ||
*/ | ||
void vexcodeInit( void ) { | ||
// nothing to initialize | ||
} |
Oops, something went wrong.