diff --git a/Ri3D_2024_off.v5code b/Ri3D_2024.v5code similarity index 100% rename from Ri3D_2024_off.v5code rename to Ri3D_2024.v5code diff --git a/src/main.cpp b/src/main.cpp index 920b871..b97dbdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,174 +1,174 @@ -/*----------------------------------------------------------------------------*/ -/* */ -/* 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 -#include "joystick.cpp" - -using namespace vex; - -competition Competition; - -motor leftFrontDriveMotor = motor(PORT17, ratio18_1, false); -motor leftBackDriveMotor = motor(PORT19, ratio18_1, false); -motor rightFrontDriveMotor = motor(PORT7, ratio18_1, false); -motor rightBackDriveMotor = motor(PORT8, ratio18_1, false); -motor frontDriveMotor = motor(PORT9, ratio18_1, true); -motor backDriveMotor = motor(PORT20, ratio18_1, false); -inertial inertialSens = inertial(PORT4); -motor arm = motor(PORT1, ratio36_1, false); -motor deploy = motor(PORT2, ratio18_1, false); -motor climbMotorA = motor(PORT6, ratio36_1, false); -motor climbMotorB = motor(PORT16, ratio36_1, true); -motor_group climb = motor_group(climbMotorA, climbMotorB); -motor_group leftDrive = motor_group(leftFrontDriveMotor, leftBackDriveMotor); -motor_group rightDrive = motor_group(rightFrontDriveMotor, rightBackDriveMotor); -//using the climb group to run the new arm group to have two different motor carts run in tandem -controller con1 = controller(primary); - - -class Drives { - public: - void static robotOriented(double xIn, double yIn, double turnIn) { - double leftMotor = yIn + turnIn; - double rightMotor = -yIn + turnIn; - double frontMotor = xIn + turnIn; - double backMotor = -xIn + turnIn; - - leftDrive.spin(fwd, leftMotor, velocityUnits::pct); - rightDrive.spin(fwd, rightMotor, velocityUnits::pct); - frontDriveMotor.spin(fwd, frontMotor, velocityUnits::pct); - backDriveMotor.spin(fwd, backMotor, velocityUnits::pct); - } - - void static fieldOriented() { - double headingRadians = inertialSens.heading() * 3.141592/180; - double yInput = getLeftY(con1, 5); - double xInput = getLeftX(con1, 5); - double sineHeading = sin(headingRadians); - double cosHeading = cos(headingRadians); - double rotatedYInput = xInput * sineHeading + yInput * cosHeading; - double rotatedXInput = xInput * cosHeading - yInput * sineHeading; - double turning = getTrueRightX(con1, 5); - double leftMotor = rotatedYInput + turning; - double rightMotor = -rotatedYInput + turning; - double FrontMotor = rotatedXInput + turning; - double backMotor = -rotatedXInput + turning; - - leftDrive.spin(fwd, leftMotor, velocityUnits::pct); - rightDrive.spin(fwd, rightMotor, velocityUnits::pct); - frontDriveMotor.spin(fwd, FrontMotor, velocityUnits::pct); - backDriveMotor.spin(fwd, backMotor, velocityUnits::pct); - } -}; - -void usercontrol(void) { - - while(true) { - Drives::fieldOriented(); - //zeroes inertial sensor - if(con1.ButtonY.pressing()) { - inertialSens.setHeading(0.0, degrees); - inertialSens.setRotation(0.0, degrees); - inertialSens.startCalibration(); - while (inertialSens.isCalibrating()) { - task::sleep(10); - } - inertialSens.setHeading(0.0, degrees); - inertialSens.setRotation(0.0, degrees); - } - if(con1.ButtonLeft.pressing()) { - climbMotorA.setStopping(brake); - climbMotorB.setStopping(brake); - } - if(con1.ButtonRight.pressing()) { - climbMotorA.setStopping(hold); - climbMotorB.setStopping(hold); - } - if(con1.ButtonUp.pressing()) { - climb.setStopping(hold); - } - if(con1.ButtonDown.pressing()) { - climb.setStopping(coast); - } - if (con1.ButtonR1.pressing()) { - climb.spin(forward); - climb.setStopping(hold); - } else if (con1.ButtonR2.pressing()) { - climb.spin(reverse); - climb.setStopping(hold); - } else { - climb.stop(); - } - wait(20,msec); - } - } - - -void auton(void) { - //Defensive side code below Save to slot 2 - //Drives::robotOriented(0.0,0.0,-25); - //task::sleep(1500); - //Drives::robotOriented(0.0, 50, 0); - // task::sleep(2000); - //Drives::robotOriented(0.0, 0.0, 0); - //Drives::robotOriented(0.0, -50, 0.0); - // task::sleep(1000); - // Drives::robotOriented(0.0, 0.0,-25); - // task::sleep(1200); -// Drives::robotOriented(0.0, 0.0, 0); -//Offensive side code below save to slot 3 - Drives::robotOriented(0.0,0.0,-15); - task::sleep(1200); - Drives::robotOriented(0.0, 50, 0); - task::sleep(2000); - Drives::robotOriented(0.0, 0.0, 0); - Drives::robotOriented(0.0, -50, 0.0); - task::sleep(1000); - climb.spin(reverse); - Drives::robotOriented(0.0, 0.0, 0); - task::sleep(1000); - climb.stop(); - -} - -int main() { - climb.setMaxTorque(100, pct); - climb.setVelocity(100, pct); - climbMotorA.setVelocity(100, pct); - climbMotorB.setVelocity(100, pct); - climbMotorA.setMaxTorque(100, pct); - climbMotorB.setMaxTorque(100, pct); - climb.setStopping(coast); - - // Initializing Robot Configuration. DO NOT REMOVE! - vexcodeInit(); - - inertialSens.setHeading(0.0, degrees); - inertialSens.setRotation(0.0, degrees); - inertialSens.startCalibration(); - while(inertialSens.isCalibrating()) { - task::sleep(10); - } - inertialSens.setHeading(0.0, degrees); - inertialSens.setRotation(0.0, degrees); - - Competition.autonomous(auton); - Competition.drivercontrol(usercontrol); - - while(true) { - task::sleep(10); - } - -} +/*----------------------------------------------------------------------------*/ +/* */ +/* 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 +#include "joystick.cpp" + +using namespace vex; + +competition Competition; + +motor leftFrontDriveMotor = motor(PORT17, ratio18_1, false); +motor leftBackDriveMotor = motor(PORT19, ratio18_1, false); +motor rightFrontDriveMotor = motor(PORT7, ratio18_1, false); +motor rightBackDriveMotor = motor(PORT8, ratio18_1, false); +motor frontDriveMotor = motor(PORT9, ratio18_1, true); +motor backDriveMotor = motor(PORT20, ratio18_1, false); +inertial inertialSens = inertial(PORT4); +motor deploy = motor(PORT2, ratio18_1, false); +motor climbMotorA = motor(PORT6, ratio18_1, false); +motor climbMotorB = motor(PORT16, ratio18_1, true); +motor_group climb = motor_group(climbMotorA, climbMotorB); +motor_group leftDrive = motor_group(leftFrontDriveMotor, leftBackDriveMotor); +motor_group rightDrive = motor_group(rightFrontDriveMotor, rightBackDriveMotor); +//using the climb group to run the new arm group to have two different motor carts run in tandem +controller con1 = controller(primary); + + +class Drives { + public: + void static robotOriented(double xIn, double yIn, double turnIn) { + double leftMotor = yIn + turnIn; + double rightMotor = -yIn + turnIn; + double frontMotor = xIn + turnIn; + double backMotor = -xIn + turnIn; + + leftDrive.spin(fwd, leftMotor, velocityUnits::pct); + rightDrive.spin(fwd, rightMotor, velocityUnits::pct); + frontDriveMotor.spin(fwd, frontMotor, velocityUnits::pct); + backDriveMotor.spin(fwd, backMotor, velocityUnits::pct); + } + + void static fieldOriented() { + double headingRadians = inertialSens.heading() * 3.141592/180; + double yInput = getLeftY(con1, 5); + double xInput = getLeftX(con1, 5); + double sineHeading = sin(headingRadians); + double cosHeading = cos(headingRadians); + double rotatedYInput = xInput * sineHeading + yInput * cosHeading; + double rotatedXInput = xInput * cosHeading - yInput * sineHeading; + double turning = getTrueRightX(con1, 5); + double leftMotor = rotatedYInput + turning; + double rightMotor = -rotatedYInput + turning; + double FrontMotor = rotatedXInput + turning; + double backMotor = -rotatedXInput + turning; + + leftDrive.spin(fwd, leftMotor, velocityUnits::pct); + rightDrive.spin(fwd, rightMotor, velocityUnits::pct); + frontDriveMotor.spin(fwd, FrontMotor, velocityUnits::pct); + backDriveMotor.spin(fwd, backMotor, velocityUnits::pct); + } +}; + +void usercontrol(void) { + + while(true) { + Drives::fieldOriented(); + //zeroes inertial sensor + if(con1.ButtonY.pressing()) { + inertialSens.setHeading(0.0, degrees); + inertialSens.setRotation(0.0, degrees); + inertialSens.startCalibration(); + while (inertialSens.isCalibrating()) { + task::sleep(10); + } + inertialSens.setHeading(0.0, degrees); + inertialSens.setRotation(0.0, degrees); + } + if(con1.ButtonLeft.pressing()) { + climbMotorA.setStopping(brake); + climbMotorB.setStopping(brake); + } + if(con1.ButtonRight.pressing()) { + climbMotorA.setStopping(hold); + climbMotorB.setStopping(hold); + } + if(con1.ButtonUp.pressing()) { + climb.setStopping(hold); + } + if(con1.ButtonDown.pressing()) { + climb.setStopping(coast); + } + if (con1.ButtonR1.pressing()) { + climb.spin(forward); + climb.setStopping(hold); + } else if (con1.ButtonR2.pressing()) { + climb.spin(reverse); + climb.setStopping(hold); + } else { + climb.stop(); + } + wait(20,msec); + } + } + + +void auton(void) { + // Defensive side code below Save to slot 2 + Drives::robotOriented(0.0, 0.0, -25); + task::sleep(1500); + Drives::robotOriented(0.0, 50, 0); + task::sleep(2000); + Drives::robotOriented(0.0, 0.0, 0); + Drives::robotOriented(0.0, -50, 0.0); + task::sleep(1000); + Drives::robotOriented(0.0, 0.0, -25); + task::sleep(1200); + Drives::robotOriented(0.0, 0.0, 0); + +//Offensive side code below save to slot 3 + // Drives::robotOriented(0.0,0.0,-15); + // task::sleep(1200); + // Drives::robotOriented(0.0, 50, 0); + // task::sleep(2000); + // Drives::robotOriented(0.0, 0.0, 0); + // Drives::robotOriented(0.0, -50, 0.0); + // task::sleep(1000); + // climb.spin(reverse); + // Drives::robotOriented(0.0, 0.0, 0); + // task::sleep(1000); + // climb.stop(); + +} + +int main() { + climb.setMaxTorque(100, pct); + climb.setVelocity(100, pct); + climbMotorA.setVelocity(100, pct); + climbMotorB.setVelocity(100, pct); + climbMotorA.setMaxTorque(100, pct); + climbMotorB.setMaxTorque(100, pct); + climb.setStopping(coast); + + // Initializing Robot Configuration. DO NOT REMOVE! + vexcodeInit(); + + inertialSens.setHeading(0.0, degrees); + inertialSens.setRotation(0.0, degrees); + inertialSens.startCalibration(); + while(inertialSens.isCalibrating()) { + task::sleep(10); + } + inertialSens.setHeading(0.0, degrees); + inertialSens.setRotation(0.0, degrees); + + Competition.autonomous(auton); + Competition.drivercontrol(usercontrol); + + while(true) { + task::sleep(10); + } + +} diff --git a/vex/mkenv.mk b/vex/mkenv.mk index f420da0..3a45b94 100644 --- a/vex/mkenv.mk +++ b/vex/mkenv.mk @@ -1,101 +1,101 @@ -# VEXcode mkenv.mk 2019_06_06_01 - -# macros to help with windows paths that include spaces -sp := -sp += -qs = $(subst ?,$(sp),$1) -sq = $(subst $(sp),?,$1) - -# default platform and build location -PLATFORM = vexv5 -BUILD = build - -# version for clang headers -ifneq ("$(origin HEADERS)", "command line") -HEADERS = 8.0.0 -endif - -# Project name passed from app -ifeq ("$(origin P)", "command line") -PROJECT = $(P) -else -PROJECT = $(notdir $(call sq,$(abspath ${CURDIR}))) -endif - -# Toolchain path passed from app -ifeq ("$(origin T)", "command line") -TOOLCHAIN = $(T) -endif -ifndef TOOLCHAIN -TOOLCHAIN = ${HOME}/sdk -endif - -# Verbose flag passed from app -ifeq ("$(origin V)", "command line") -BUILD_VERBOSE=$(V) -endif - -# allow verbose to be set by makefile if not set by app -ifndef BUILD_VERBOSE -ifndef VERBOSE -BUILD_VERBOSE = 0 -else -BUILD_VERBOSE = $(VERBOSE) -endif -endif - -# use verbose flag -ifeq ($(BUILD_VERBOSE),0) -Q = @ -else -Q = -endif - -# compile and link tools -CC = clang -CXX = clang -OBJCOPY = arm-none-eabi-objcopy -SIZE = arm-none-eabi-size -LINK = arm-none-eabi-ld -ARCH = arm-none-eabi-ar -ECHO = @echo -DEFINES = -DVexV5 - -# platform specific macros -ifeq ($(OS),Windows_NT) -$(info windows build for platform $(PLATFORM)) -SHELL = cmd.exe -MKDIR = md "$(@D)" 2> nul || : -RMDIR = rmdir /S /Q -CLEAN = $(RMDIR) $(BUILD) 2> nul || : -else -$(info unix build for platform $(PLATFORM)) -MKDIR = mkdir -p "$(@D)" 2> /dev/null || : -RMDIR = rm -rf -CLEAN = $(RMDIR) $(BUILD) 2> /dev/null || : -endif - -# toolchain include and lib locations -TOOL_INC = -I"$(TOOLCHAIN)/$(PLATFORM)/clang/$(HEADERS)/include" -I"$(TOOLCHAIN)/$(PLATFORM)/gcc/include" -I"$(TOOLCHAIN)/$(PLATFORM)/gcc/include/c++/4.9.3" -I"$(TOOLCHAIN)/$(PLATFORM)/gcc/include/c++/4.9.3/arm-none-eabi/armv7-ar/thumb" -TOOL_LIB = -L"$(TOOLCHAIN)/$(PLATFORM)/gcc/libs" - -# compiler flags -CFLAGS_CL = -target thumbv7-none-eabi -fshort-enums -Wno-unknown-attributes -U__INT32_TYPE__ -U__UINT32_TYPE__ -D__INT32_TYPE__=long -D__UINT32_TYPE__='unsigned long' -CFLAGS_V7 = -march=armv7-a -mfpu=neon -mfloat-abi=softfp -CFLAGS = ${CFLAGS_CL} ${CFLAGS_V7} -Os -Wall -Werror=return-type -ansi -std=gnu99 $(DEFINES) -CXX_FLAGS = ${CFLAGS_CL} ${CFLAGS_V7} -Os -Wall -Werror=return-type -fno-rtti -fno-threadsafe-statics -fno-exceptions -std=gnu++11 -ffunction-sections -fdata-sections $(DEFINES) - -# linker flags -LNK_FLAGS = -nostdlib -T "$(TOOLCHAIN)/$(PLATFORM)/lscript.ld" -R "$(TOOLCHAIN)/$(PLATFORM)/stdlib_0.lib" -Map="$(BUILD)/$(PROJECT).map" --gc-section -L"$(TOOLCHAIN)/$(PLATFORM)" ${TOOL_LIB} - -# future statuc library -PROJECTLIB = lib$(PROJECT) -ARCH_FLAGS = rcs - -# libraries -LIBS = --start-group -lv5rt -lstdc++ -lc -lm -lgcc --end-group - -# include file paths -INC += $(addprefix -I, ${INC_F}) -INC += -I"$(TOOLCHAIN)/$(PLATFORM)/include" -INC += ${TOOL_INC} +# VEXcode mkenv.mk 2019_06_06_01 + +# macros to help with windows paths that include spaces +sp := +sp += +qs = $(subst ?,$(sp),$1) +sq = $(subst $(sp),?,$1) + +# default platform and build location +PLATFORM = vexv5 +BUILD = build + +# version for clang headers +ifneq ("$(origin HEADERS)", "command line") +HEADERS = 8.0.0 +endif + +# Project name passed from app +ifeq ("$(origin P)", "command line") +PROJECT = $(P) +else +PROJECT = $(notdir $(call sq,$(abspath ${CURDIR}))) +endif + +# Toolchain path passed from app +ifeq ("$(origin T)", "command line") +TOOLCHAIN = $(T) +endif +ifndef TOOLCHAIN +TOOLCHAIN = ${HOME}/sdk +endif + +# Verbose flag passed from app +ifeq ("$(origin V)", "command line") +BUILD_VERBOSE=$(V) +endif + +# allow verbose to be set by makefile if not set by app +ifndef BUILD_VERBOSE +ifndef VERBOSE +BUILD_VERBOSE = 0 +else +BUILD_VERBOSE = $(VERBOSE) +endif +endif + +# use verbose flag +ifeq ($(BUILD_VERBOSE),0) +Q = @ +else +Q = +endif + +# compile and link tools +CC = clang +CXX = clang +OBJCOPY = arm-none-eabi-objcopy +SIZE = arm-none-eabi-size +LINK = arm-none-eabi-ld +ARCH = arm-none-eabi-ar +ECHO = @echo +DEFINES = -DVexV5 + +# platform specific macros +ifeq ($(OS),Windows_NT) +$(info windows build for platform $(PLATFORM)) +SHELL = cmd.exe +MKDIR = md "$(@D)" 2> nul || : +RMDIR = rmdir /S /Q +CLEAN = $(RMDIR) $(BUILD) 2> nul || : +else +$(info unix build for platform $(PLATFORM)) +MKDIR = mkdir -p "$(@D)" 2> /dev/null || : +RMDIR = rm -rf +CLEAN = $(RMDIR) $(BUILD) 2> /dev/null || : +endif + +# toolchain include and lib locations +TOOL_INC = -I"$(TOOLCHAIN)/$(PLATFORM)/clang/$(HEADERS)/include" -I"$(TOOLCHAIN)/$(PLATFORM)/gcc/include" -I"$(TOOLCHAIN)/$(PLATFORM)/gcc/include/c++/4.9.3" -I"$(TOOLCHAIN)/$(PLATFORM)/gcc/include/c++/4.9.3/arm-none-eabi/armv7-ar/thumb" +TOOL_LIB = -L"$(TOOLCHAIN)/$(PLATFORM)/gcc/libs" + +# compiler flags +CFLAGS_CL = -target thumbv7-none-eabi -fshort-enums -Wno-unknown-attributes -U__INT32_TYPE__ -U__UINT32_TYPE__ -D__INT32_TYPE__=long -D__UINT32_TYPE__='unsigned long' +CFLAGS_V7 = -march=armv7-a -mfpu=neon -mfloat-abi=softfp +CFLAGS = ${CFLAGS_CL} ${CFLAGS_V7} -Os -Wall -Werror=return-type -ansi -std=gnu99 $(DEFINES) +CXX_FLAGS = ${CFLAGS_CL} ${CFLAGS_V7} -Os -Wall -Werror=return-type -fno-rtti -fno-threadsafe-statics -fno-exceptions -std=gnu++11 -ffunction-sections -fdata-sections $(DEFINES) + +# linker flags +LNK_FLAGS = -nostdlib -T "$(TOOLCHAIN)/$(PLATFORM)/lscript.ld" -R "$(TOOLCHAIN)/$(PLATFORM)/stdlib_0.lib" -Map="$(BUILD)/$(PROJECT).map" --gc-section -L"$(TOOLCHAIN)/$(PLATFORM)" ${TOOL_LIB} + +# future statuc library +PROJECTLIB = lib$(PROJECT) +ARCH_FLAGS = rcs + +# libraries +LIBS = --start-group -lv5rt -lstdc++ -lc -lm -lgcc --end-group + +# include file paths +INC += $(addprefix -I, ${INC_F}) +INC += -I"$(TOOLCHAIN)/$(PLATFORM)/include" +INC += ${TOOL_INC} diff --git a/vex/mkrules.mk b/vex/mkrules.mk index a45bbdc..eb29f1f 100644 --- a/vex/mkrules.mk +++ b/vex/mkrules.mk @@ -1,32 +1,32 @@ -# VEXcode mkrules.mk 2019_03_26_01 - -# compile C files -$(BUILD)/%.o: %.c $(SRC_H) - $(Q)$(MKDIR) - $(ECHO) "CC $<" - $(Q)$(CC) $(CFLAGS) $(INC) -c -o $@ $< - -# compile C++ files -$(BUILD)/%.o: %.cpp $(SRC_H) $(SRC_A) - $(Q)$(MKDIR) - $(ECHO) "CXX $<" - $(Q)$(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $< - -# create executable -$(BUILD)/$(PROJECT).elf: $(OBJ) - $(ECHO) "LINK $@" - $(Q)$(LINK) $(LNK_FLAGS) -o $@ $^ $(LIBS) - $(Q)$(SIZE) $@ - -# create binary -$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf - $(Q)$(OBJCOPY) -O binary $(BUILD)/$(PROJECT).elf $(BUILD)/$(PROJECT).bin - -# create archive -$(BUILD)/$(PROJECTLIB).a: $(OBJ) - $(Q)$(ARCH) $(ARCH_FLAGS) $@ $^ - -# clean project -clean: - $(info clean project) - $(Q)$(CLEAN) +# VEXcode mkrules.mk 2019_03_26_01 + +# compile C files +$(BUILD)/%.o: %.c $(SRC_H) + $(Q)$(MKDIR) + $(ECHO) "CC $<" + $(Q)$(CC) $(CFLAGS) $(INC) -c -o $@ $< + +# compile C++ files +$(BUILD)/%.o: %.cpp $(SRC_H) $(SRC_A) + $(Q)$(MKDIR) + $(ECHO) "CXX $<" + $(Q)$(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $< + +# create executable +$(BUILD)/$(PROJECT).elf: $(OBJ) + $(ECHO) "LINK $@" + $(Q)$(LINK) $(LNK_FLAGS) -o $@ $^ $(LIBS) + $(Q)$(SIZE) $@ + +# create binary +$(BUILD)/$(PROJECT).bin: $(BUILD)/$(PROJECT).elf + $(Q)$(OBJCOPY) -O binary $(BUILD)/$(PROJECT).elf $(BUILD)/$(PROJECT).bin + +# create archive +$(BUILD)/$(PROJECTLIB).a: $(OBJ) + $(Q)$(ARCH) $(ARCH_FLAGS) $@ $^ + +# clean project +clean: + $(info clean project) + $(Q)$(CLEAN)