Initial commit
commit
c05b9462ad
@ -0,0 +1 @@
|
||||
{"title":"38535A-4","description":"Empty V5 C++ Project","icon":"USER921x.bmp","version":"19.10.1015","sdk":"20200203_11_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":"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":2,"uid":"276-4810","options":{}},"isExpertMode":true,"isExpertModeRC":true,"isVexFileImport":false,"robotconfig":[],"neverUpdate":null}
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
[{"directory":"C:/Users/Cole/Documents/cad/38535A-4","file":"include/robot-config.h","arguments":["clang","-xc++","include/robot-config.h","-include","v5_vcs.h","--target=thumbv7-none-eabi","-U","__INT32_TYPE__","-U","__UINT32_TYPE__","-D","__INT32_TYPE__=long","-D","__UINT32_TYPE__=unsigned long","-std=gnu++11","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/clang/8.0.0/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3/arm-none-eabi/armv7-ar/thumb"]},{"directory":"C:/Users/Cole/Documents/cad/38535A-4","file":"include/vex.h","arguments":["clang","-xc++","include/vex.h","-include","v5_vcs.h","--target=thumbv7-none-eabi","-U","__INT32_TYPE__","-U","__UINT32_TYPE__","-D","__INT32_TYPE__=long","-D","__UINT32_TYPE__=unsigned long","-std=gnu++11","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/clang/8.0.0/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3/arm-none-eabi/armv7-ar/thumb"]},{"directory":"C:/Users/Cole/Documents/cad/38535A-4","file":"src/main.cpp","output":"build/src/main.o","arguments":["clang","-xc++","src/main.cpp","--target=thumbv7-none-eabi","-fshort-enums","-Wno-unknown-attributes","-U","__INT32_TYPE__","-U","__UINT32_TYPE__","-D","__INT32_TYPE__=long","-D","__UINT32_TYPE__=unsigned long","-march=armv7-a","-mfpu=neon","-mfloat-abi=softfp","-Os","-Wall","-Werror=return-type","-fno-rtti","-fno-threadsafe-statics","-fno-exceptions","-std=gnu++11","-ffunction-sections","-fdata-sections","-D","VexV5","-I",".","-I","include","-I","src","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/clang/8.0.0/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3/arm-none-eabi/armv7-ar/thumb","-c","-o","build/src/main.o","-mlinker-version=409.12","--target=armv7-none--eabi"]},{"directory":"C:/Users/Cole/Documents/cad/38535A-4","file":"src/robot-config.cpp","output":"build/src/robot-config.o","arguments":["clang","-xc++","src/robot-config.cpp","--target=thumbv7-none-eabi","-fshort-enums","-Wno-unknown-attributes","-U","__INT32_TYPE__","-U","__UINT32_TYPE__","-D","__INT32_TYPE__=long","-D","__UINT32_TYPE__=unsigned long","-march=armv7-a","-mfpu=neon","-mfloat-abi=softfp","-Os","-Wall","-Werror=return-type","-fno-rtti","-fno-threadsafe-statics","-fno-exceptions","-std=gnu++11","-ffunction-sections","-fdata-sections","-D","VexV5","-I",".","-I","include","-I","src","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/clang/8.0.0/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3","-I","C:/Program Files (x86)/VEX Robotics/VEXcode V5 Text/sdk/vexv5/gcc/include/c++/4.9.3/arm-none-eabi/armv7-ar/thumb","-c","-o","build/src/robot-config.o","-mlinker-version=409.12","--target=armv7-none--eabi"]}]
|
@ -0,0 +1,19 @@
|
||||
using namespace vex;
|
||||
|
||||
extern brain Brain;
|
||||
|
||||
// VEXcode devices
|
||||
extern drivetrain Drivetrain;
|
||||
extern motor LiftMotor;
|
||||
extern motor LiftMotor2;
|
||||
extern motor TiltMotor;
|
||||
extern controller Controller1;
|
||||
extern motor IntakeR;
|
||||
extern motor IntakeL;
|
||||
|
||||
/**
|
||||
* Used to initialize code/tasks/devices added using tools in VEXcode Text.
|
||||
*
|
||||
* This should be called at the start of your int main function.
|
||||
*/
|
||||
void vexcodeInit( void );
|
@ -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++)
|
@ -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
|
@ -0,0 +1,562 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* Module: main.cpp */
|
||||
/* Author: VEX */
|
||||
/* Created: Thu Sep 26 2019 */
|
||||
/* Description: Competition Template */
|
||||
/* */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
// ---- START VEXCODE CONFIGURED DEVICES ----
|
||||
// Robot Configuration:
|
||||
// [Name] [Type] [Port(s)]
|
||||
// Drivetrain drivetrain 10, 1
|
||||
// LiftMotor motor 9
|
||||
// TiltMotor motor 8
|
||||
// Controller1 controller
|
||||
// IntakeR motor 2
|
||||
// IntakeL motor 3
|
||||
// ---- END VEXCODE CONFIGURED DEVICES ----
|
||||
|
||||
#include "vex.h"
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
using namespace vex;
|
||||
bool speedin = true;
|
||||
double driveMultiplier = 1.0;
|
||||
|
||||
bool apressed = false;
|
||||
bool bpressed = false;
|
||||
// A global instance of competition
|
||||
competition Competition;
|
||||
|
||||
motor LeftDriveSmart = motor(PORT1, ratio18_1, false);
|
||||
motor RightDriveSmart = motor(PORT2, ratio18_1, true);
|
||||
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 130, mm, 1);
|
||||
motor LiftMotor = motor(PORT18, ratio18_1, true);
|
||||
motor LiftMotor2 = motor(PORT12, ratio18_1, false);
|
||||
motor TiltMotor = motor(PORT3, ratio18_1, false);
|
||||
controller Controller1 = controller(primary);
|
||||
motor IntakeR = motor(PORT17, ratio18_1, false);
|
||||
motor IntakeL = motor(PORT8, ratio18_1, true);
|
||||
|
||||
bool Controller1LeftShoulderControlMotorsStopped = true;
|
||||
bool Controller1RightShoulderControlMotorsStopped = true;
|
||||
bool Controller1UpDownButtonsControlMotorsStopped = true;
|
||||
bool DrivetrainLNeedsToBeStopped_Controller1 = true;
|
||||
bool DrivetrainRNeedsToBeStopped_Controller1 = true;
|
||||
bool IntakeStop = true;
|
||||
void controllerBaseInput();
|
||||
void STOPCODE_DEBUG();
|
||||
// define your global instances of motors and other devices here
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Pre-Autonomous Functions */
|
||||
/* */
|
||||
/* You may want to perform some actions before the competition starts. */
|
||||
/* Do them in the following function. You must return from this function */
|
||||
/* or the autonomous and usercontrol tasks will not be started. This */
|
||||
/* function is only called once after the V5 has been powered on and */
|
||||
/* not every time that the robot is disabled. */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void pre_auton(void) {
|
||||
// Initializing Robot Configuration. DO NOT REMOVE!
|
||||
vexcodeInit();
|
||||
|
||||
// All activities that occur before the competition starts
|
||||
// Example: clearing encoders, setting servo positions, ...
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* Autonomous Task */
|
||||
/* */
|
||||
/* This task is used to control your robot during the autonomous phase of */
|
||||
/* a VEX Competition. */
|
||||
/* */
|
||||
/* You must modify the code to add your own robot specific commands here. */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
std::ifstream ifs;
|
||||
void autonomous(void) {
|
||||
// ..........................................................................
|
||||
// Insert autonomous user code here.
|
||||
// ..........................................................................
|
||||
/*STOPCODE_DEBUG();
|
||||
LiftMotor.setVelocity(100, percent);
|
||||
LiftMotor2.setVelocity(100, percent);
|
||||
TiltMotor.setVelocity(30, percent);
|
||||
//Drivetrain.driveFor(6, inches);*/
|
||||
LiftMotor.resetRotation();
|
||||
LiftMotor2.resetRotation();
|
||||
TiltMotor.resetRotation();
|
||||
IntakeL.resetRotation();
|
||||
IntakeR.resetRotation();
|
||||
LeftDriveSmart.resetRotation();
|
||||
RightDriveSmart.resetRotation();
|
||||
|
||||
LiftMotor.setStopping(hold);
|
||||
LiftMotor2.setStopping(hold);
|
||||
//STOPCODE_DEBUG();
|
||||
//uint8_t * instructions = nullptr;
|
||||
//Brain.SDcard.loadfile("recording.bin", instructions, 2500); // size in bytes
|
||||
ifs.open("recording.txt", std::ofstream::in);
|
||||
Controller1.Screen.print("File opened");
|
||||
std::string instructions;
|
||||
while(std::getline(ifs, instructions)) {
|
||||
int y = 0;
|
||||
y = instructions.find(" ", 5);
|
||||
double vel = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
y = instructions.find(" ", 5);
|
||||
double pos = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
Controller1.Screen.print(vel);
|
||||
LeftDriveSmart.rotateTo(pos, degrees, vel, velocityUnits::pct, false);
|
||||
|
||||
y = instructions.find(" ", 5);
|
||||
vel = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
y = instructions.find(" ", 5);
|
||||
pos = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
Controller1.Screen.print(vel);
|
||||
RightDriveSmart.rotateTo(pos, degrees, vel, velocityUnits::pct, false);
|
||||
|
||||
y = instructions.find(" ", 5);
|
||||
vel = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
IntakeL.spin(forward, vel, percent);
|
||||
IntakeR.spin(forward, vel, percent);
|
||||
|
||||
y = instructions.find(" ", 5);
|
||||
vel = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
y = instructions.find(" ", 5);
|
||||
pos = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
LiftMotor.rotateTo(pos, degrees, vel, velocityUnits::pct, false);
|
||||
LiftMotor2.rotateTo(pos, degrees, vel, velocityUnits::pct, false);
|
||||
|
||||
y = instructions.find(" ", 5);
|
||||
vel = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
y = instructions.find(" ", 5);
|
||||
pos = strtod(instructions.substr(0, y).c_str(), NULL);
|
||||
instructions = instructions.substr(y + 1);
|
||||
TiltMotor.rotateTo(pos, degrees, vel, velocityUnits::pct, false);
|
||||
wait(20, msec);
|
||||
}
|
||||
ifs.close();
|
||||
STOPCODE_DEBUG();
|
||||
Drivetrain.setDriveVelocity(40, percent);
|
||||
Drivetrain.setTurnVelocity(50, percent);
|
||||
// Drivetrain.turnFor(5, degrees);
|
||||
Drivetrain.driveFor(15, inches, false);
|
||||
wait(2, sec);
|
||||
Drivetrain.setDriveVelocity(80, percent);
|
||||
Drivetrain.driveFor(reverse, 16, inches);
|
||||
wait(1, sec);
|
||||
//Drivetrain.turnFor(-45, degrees);
|
||||
STOPCODE_DEBUG();
|
||||
LiftMotor.startSpinTo(40 * 7, degrees); // unlock everything
|
||||
LiftMotor2.startSpinTo(40 * 7, degrees);
|
||||
waitUntil(LiftMotor.isDone() && LiftMotor2.isDone());
|
||||
TiltMotor.startSpinTo(45 * 7, degrees);
|
||||
LiftMotor.startSpinTo(10 * 7, degrees);
|
||||
LiftMotor2.startSpinTo(10 * 7, degrees);
|
||||
waitUntil(LiftMotor.isDone() && LiftMotor2.isDone() && TiltMotor.isDone());
|
||||
IntakeL.setVelocity(100, percent);
|
||||
IntakeR.setVelocity(100, percent);
|
||||
IntakeL.startSpinTo(-5, rev);
|
||||
IntakeR.startSpinTo(-5, rev);
|
||||
TiltMotor.startSpinTo(5, degrees);
|
||||
waitUntil(TiltMotor.isDone());
|
||||
//STOPCODE_DEBUG();
|
||||
STOPCODE_DEBUG();
|
||||
IntakeL.setVelocity(100, percent);
|
||||
IntakeR.setVelocity(100, percent);
|
||||
//IntakeL.startSpinTo(5, rev); // grab preload
|
||||
//IntakeR.startSpinTo(5, rev);
|
||||
Drivetrain.setDriveVelocity(80, percent);
|
||||
Drivetrain.setTurnVelocity(100, percent);
|
||||
|
||||
//Drivetrain.driveFor(24 * 3.5, inches); // drive to the row of 4 (if on that tile)
|
||||
waitUntil(IntakeL.isDone() && IntakeR.isDone());
|
||||
//Drivetrain.turnFor(-90, degrees); // turn LEFT
|
||||
IntakeL.spin(forward);
|
||||
IntakeR.spin(forward);
|
||||
Drivetrain.setDriveVelocity(50, percent);
|
||||
Drivetrain.driveFor(24 * 0.8, inches); // grab 4 cubes
|
||||
wait(1000, msec);
|
||||
IntakeL.stop(hold);
|
||||
IntakeR.stop(hold); // hold the cubes
|
||||
STOPCODE_DEBUG();
|
||||
Drivetrain.driveFor(reverse, 24 * 1.6, inches); // go back
|
||||
Drivetrain.setTurnVelocity(50, percent);
|
||||
Drivetrain.turnFor(130, degrees); // turn RIGHT towards corner
|
||||
Drivetrain.setDriveVelocity(33, percent);
|
||||
Drivetrain.driveFor(24 * 0.8, inches); // go to corner
|
||||
TiltMotor.spinTo(50 * 7, degrees); // tilt cubes
|
||||
IntakeL.setVelocity(20, percent);
|
||||
IntakeR.setVelocity(20, percent);
|
||||
IntakeL.startSpinFor(-3, rev);
|
||||
IntakeR.startSpinFor(-3, rev); // start pushing out cubes
|
||||
Drivetrain.setDriveVelocity(25, percent);
|
||||
Drivetrain.driveFor(reverse, 24 * 0.8, inches); // back away slowly
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* User Control Task */
|
||||
/* */
|
||||
/* This task is used to control your robot during the user control phase of */
|
||||
/* a VEX Competition. */
|
||||
/* */
|
||||
/* You must modify the code to add your own robot specific commands here. */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
std::ofstream ofs;
|
||||
|
||||
void usercontrol(void) {
|
||||
LiftMotor.setVelocity(100, percent);
|
||||
LiftMotor2.setVelocity(100, percent);
|
||||
TiltMotor.setVelocity(30, percent);
|
||||
Controller1.Screen.clearScreen();
|
||||
Controller1.Screen.setCursor(0, 0);
|
||||
Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Normal Driving ");
|
||||
bool recording = false;
|
||||
bool donerecording = false;
|
||||
//uint8_t * data = (uint8_t*)malloc(sizeof(uint8_t) * 5);
|
||||
|
||||
// User control code here, inside the loop
|
||||
while (1) {
|
||||
// This is the main execution loop for the user control program.
|
||||
// Each time through the loop your program should update motor + servo
|
||||
// values based on feedback from the joysticks.
|
||||
|
||||
// ........................................................................
|
||||
// Insert user code here. This is where you use the joystick values to
|
||||
// update your motors, etc.
|
||||
// ........................................................................
|
||||
if(Controller1.ButtonY.pressing()) {
|
||||
speedin = false;
|
||||
driveMultiplier = 0.33;
|
||||
Controller1.Screen.setCursor(0, 0);
|
||||
Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Precise Driving ");
|
||||
} else if(Controller1.ButtonX.pressing()) {
|
||||
speedin = true;
|
||||
driveMultiplier = 1;
|
||||
Controller1.Screen.setCursor(0, 0);
|
||||
Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Normal Driving ");
|
||||
}
|
||||
if(Controller1.ButtonA.pressing() && !apressed) {
|
||||
speedin = !speedin;
|
||||
apressed = true;
|
||||
}
|
||||
else if(!Controller1.ButtonA.pressing()) apressed = false;
|
||||
|
||||
if(Controller1.ButtonB.pressing() && !bpressed) {
|
||||
if(driveMultiplier == 1.0) {
|
||||
driveMultiplier = 0.33;
|
||||
Controller1.Screen.setCursor(0, 0);
|
||||
//Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Precise Driving");
|
||||
}
|
||||
else if(driveMultiplier == 0.33) {
|
||||
driveMultiplier = 1;
|
||||
Controller1.Screen.setCursor(0, 0);
|
||||
//Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Normal Driving ");
|
||||
}
|
||||
bpressed = true;
|
||||
}
|
||||
else if(!Controller1.ButtonB.pressing()) bpressed = false;
|
||||
//uint8_t * data = (uint8_t*)malloc(sizeof(uint8_t) * 5);
|
||||
if(Controller1.ButtonLeft.pressing() && !recording) {
|
||||
recording = true;
|
||||
|
||||
LeftDriveSmart.resetRotation();
|
||||
RightDriveSmart.resetRotation();
|
||||
LiftMotor.resetRotation();
|
||||
LiftMotor2.resetRotation();
|
||||
TiltMotor.resetRotation();
|
||||
IntakeL.resetRotation();
|
||||
IntakeR.resetRotation();
|
||||
if (Brain.SDcard.isInserted()) {
|
||||
// create a file with long filename
|
||||
ofs.open("recording.txt", std::ofstream::out);
|
||||
}
|
||||
}
|
||||
if(Controller1.ButtonRight.pressing()) {
|
||||
donerecording = true;
|
||||
}
|
||||
if(recording) {
|
||||
//count ++;
|
||||
std::string thisReading = "";
|
||||
char output[12];
|
||||
snprintf(output, 12, "%f", LeftDriveSmart.velocity(percent));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", LeftDriveSmart.rotation(degrees));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", RightDriveSmart.velocity(percent));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", RightDriveSmart.rotation(degrees));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
|
||||
//char output[12];
|
||||
snprintf(output, 12, "%f", IntakeL.velocity(percent));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", LiftMotor.velocity(percent));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", LiftMotor.rotation(degrees));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", TiltMotor.velocity(percent));
|
||||
thisReading += output;
|
||||
thisReading += " ";
|
||||
//output[12] = "";
|
||||
snprintf(output, 12, "%f", TiltMotor.rotation(degrees));
|
||||
thisReading += output;
|
||||
thisReading += " \n";
|
||||
ofs << thisReading;
|
||||
|
||||
//data = (uint8_t*)realloc(data, sizeof(uint8_t) * 5 * count + 5);
|
||||
//uint8_t* thisReading;
|
||||
//thisReading = new uint8_t[5];
|
||||
/*thisReading = {(uint8_t) (LeftDriveSmart.velocity(percent)+100),
|
||||
(uint8_t) (RightDriveSmart.velocity(percent)+100),
|
||||
(uint8_t) (IntakeL.velocity(percent)+100),
|
||||
(uint8_t) (LiftMotor.velocity(percent)+100),
|
||||
(uint8_t) (TiltMotor.velocity(percent)+100)
|
||||
};*/
|
||||
//*(thisReading) = (uint8_t) (LeftDriveSmart.velocity(percent)+100);
|
||||
//*(thisReading+1) = (uint8_t) (RightDriveSmart.velocity(percent)+100);
|
||||
//*(thisReading+2) = (uint8_t) (IntakeL.velocity(percent)+100);
|
||||
//*(thisReading+3) = (uint8_t) (LiftMotor.velocity(percent)+100);
|
||||
//*(thisReading+4) = (uint8_t) (TiltMotor.velocity(percent)+100);
|
||||
//int startIndex = count * 5;
|
||||
//for(int i = 0; i < 5; i++) {
|
||||
// data[startIndex + i] = thisReading[i];
|
||||
//}
|
||||
if(donerecording) {
|
||||
//Brain.SDcard.savefile("recording.bin", data, sizeof(data));
|
||||
recording = false;
|
||||
ofs.close();
|
||||
}
|
||||
}
|
||||
controllerBaseInput();
|
||||
wait(20, msec); // Sleep the task for a short amount of time to
|
||||
// prevent wasted resources.
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Main will set up the competition functions and callbacks.
|
||||
//
|
||||
int main() {
|
||||
// Set up callbacks for autonomous and driver control periods.
|
||||
Competition.autonomous(autonomous);
|
||||
Competition.drivercontrol(usercontrol);
|
||||
|
||||
// Run the pre-autonomous function.
|
||||
pre_auton();
|
||||
|
||||
// Prevent main from exiting with an infinite loop.
|
||||
while (true) {
|
||||
wait(100, msec);
|
||||
}
|
||||
}
|
||||
void STOPCODE_DEBUG() {
|
||||
Drivetrain.stop();
|
||||
LiftMotor.stop();
|
||||
LiftMotor2.stop();
|
||||
IntakeR.stop();
|
||||
IntakeL.stop();
|
||||
TiltMotor.stop();
|
||||
while(true) wait(20, msec);
|
||||
}
|
||||
|
||||
void controllerBaseInput() {
|
||||
|
||||
//int drivetrainLeftSideSpeed = Controller1.Axis3.position();
|
||||
//int drivetrainRightSideSpeed = Controller1.Axis2.position();
|
||||
double axisAngle = atan2(Controller1.Axis3.position(), Controller1.Axis4.position());
|
||||
axisAngle *= 180 / 3.1415926;
|
||||
|
||||
//if(Controller1.Axis4.position() < 0) axisAngle += 180;
|
||||
//Controller1.Screen.setCursor(0, 50);
|
||||
//Controller1.Screen.clearLine();
|
||||
//Controller1.Screen.print(axisAngle);
|
||||
int drivetrainLeftSideSpeed = Controller1.Axis3.position();
|
||||
int drivetrainRightSideSpeed = Controller1.Axis4.position();
|
||||
int powerLevel = sqrt(Controller1.Axis3.position() * Controller1.Axis3.position() + Controller1.Axis4.position() * Controller1.Axis4.position());
|
||||
// left side
|
||||
if(axisAngle < 90 && axisAngle >= 0) drivetrainLeftSideSpeed = powerLevel;
|
||||
else if(axisAngle <= 181 && axisAngle >= 90) drivetrainLeftSideSpeed = int(powerLevel * (135 - axisAngle) / 45);
|
||||
else if(axisAngle >= -181 && axisAngle <= -90) drivetrainLeftSideSpeed = -powerLevel;
|
||||
else if(axisAngle > -90 && axisAngle < 0) drivetrainLeftSideSpeed = int(powerLevel * (45 + axisAngle) / 45);
|
||||
|
||||
if(axisAngle <= 181 && axisAngle >= 90) drivetrainRightSideSpeed = powerLevel;
|
||||
else if(axisAngle < 90 && axisAngle >= 0) drivetrainRightSideSpeed = -int(powerLevel * (45 - axisAngle) / 45);
|
||||
else if(axisAngle > -90 && axisAngle < 0) drivetrainRightSideSpeed = -powerLevel;
|
||||
else if(axisAngle >= -181 && axisAngle <= -90) drivetrainRightSideSpeed = -int(powerLevel * (135 + axisAngle) / 45);
|
||||
|
||||
if(Controller1.Axis4.position() == 0 && Controller1.Axis3.position() > 0 && (int(axisAngle) == 90 || int(axisAngle) == 0)) {
|
||||
drivetrainLeftSideSpeed = powerLevel;
|
||||
drivetrainRightSideSpeed = powerLevel;
|
||||
}
|
||||
if(Controller1.Axis4.position() == 0 && Controller1.Axis3.position() < 0 && (int(axisAngle) == -90 || int(axisAngle) == 0)) {
|
||||
drivetrainLeftSideSpeed = -powerLevel;
|
||||
drivetrainRightSideSpeed = -powerLevel;
|
||||
}
|
||||
if(Controller1.Axis4.position() < 0 && (int(axisAngle) == 180 || int(axisAngle) == -180 || int(axisAngle) == 0)) {
|
||||
drivetrainLeftSideSpeed = -powerLevel;
|
||||
drivetrainRightSideSpeed = powerLevel;
|
||||
}
|
||||
if(Controller1.ButtonDown.pressing()) {
|
||||
drivetrainLeftSideSpeed = -33;
|
||||
drivetrainRightSideSpeed = -33;
|
||||
}
|
||||
else if(Controller1.ButtonUp.pressing()) {
|
||||
drivetrainLeftSideSpeed = 33;
|
||||
drivetrainRightSideSpeed = 33;
|
||||
}
|
||||
else {
|
||||
drivetrainLeftSideSpeed *= driveMultiplier;
|
||||
drivetrainRightSideSpeed *= driveMultiplier;
|
||||
}
|
||||
// check if the value is inside of the deadband range
|
||||
if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
|
||||
// check if the left motor has already been stopped
|
||||
if (DrivetrainLNeedsToBeStopped_Controller1) {
|
||||
// stop the left drive motor
|
||||
LeftDriveSmart.stop();
|
||||
// tell the code that the left motor has been stopped
|
||||
DrivetrainLNeedsToBeStopped_Controller1 = false;
|
||||
}
|
||||
} else {
|
||||
// reset the toggle so that the deadband code knows to stop the left motor next time the input is in the deadband range
|
||||
DrivetrainLNeedsToBeStopped_Controller1 = true;
|
||||
}
|
||||
// check if the value is inside of the deadband range
|
||||
if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
|
||||
// check if the right motor has already been stopped
|
||||
if (DrivetrainRNeedsToBeStopped_Controller1) {
|
||||
// stop the right drive motor
|
||||
RightDriveSmart.stop();
|
||||
// tell the code that the right motor has been stopped
|
||||
DrivetrainRNeedsToBeStopped_Controller1 = false;
|
||||
}
|
||||
} else {
|
||||
// reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
|
||||
DrivetrainRNeedsToBeStopped_Controller1 = true;
|
||||
}
|
||||
// only tell the left drive motor to spin if the values are not in the deadband range
|
||||
if (DrivetrainLNeedsToBeStopped_Controller1) {
|
||||
LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
|
||||
LeftDriveSmart.spin(forward);
|
||||
}
|
||||
// only tell the right drive motor to spin if the values are not in the deadband range
|
||||
if (DrivetrainRNeedsToBeStopped_Controller1) {
|
||||
RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
|
||||
RightDriveSmart.spin(forward);
|
||||
}
|
||||
// check the ButtonL1/ButtonL2 status to control LiftMotor
|
||||
if (Controller1.ButtonL1.pressing()) {
|
||||
LiftMotor.spin(forward);
|
||||
LiftMotor2.spin(forward);
|
||||
Controller1LeftShoulderControlMotorsStopped = false;
|
||||
} else if (Controller1.ButtonL2.pressing()) {
|
||||
LiftMotor.spin(reverse);
|
||||
LiftMotor2.spin(reverse);
|
||||
Controller1LeftShoulderControlMotorsStopped = false;
|
||||
} else if (!Controller1LeftShoulderControlMotorsStopped) {
|
||||
LiftMotor.stop(hold);
|
||||
LiftMotor2.stop(hold);
|
||||
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
|
||||
Controller1LeftShoulderControlMotorsStopped = true;
|
||||
}
|
||||
int IntakeSpeed = Controller1.Axis2.position();
|
||||
if (IntakeSpeed < 5 && IntakeSpeed > -5) {
|
||||
// check if the left motor has already been stopped
|
||||
if (IntakeStop) {
|
||||
// stop the left drive motor
|
||||
IntakeL.stop();
|
||||
IntakeR.stop();
|
||||
// tell the code that the left motor has been stopped
|
||||
IntakeStop = false;
|
||||
}
|
||||
} else {
|
||||
// reset the toggle so that the deadband code knows to stop the left motor next time the input is in the deadband range
|
||||
IntakeStop = true;
|
||||
}
|
||||
// only tell the left drive motor to spin if the values are not in the deadband range
|
||||
if(speedin) {
|
||||
Controller1.Screen.setCursor(2, 0);
|
||||
//Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Fast intake");
|
||||
} else {
|
||||
Controller1.Screen.setCursor(2, 0);
|
||||
//Controller1.Screen.clearLine();
|
||||
Controller1.Screen.print("Slow intake");
|
||||
IntakeSpeed /= 4;
|
||||
}
|
||||
if (IntakeStop) {
|
||||
IntakeL.setVelocity(IntakeSpeed, percent);
|
||||
IntakeR.setVelocity(IntakeSpeed, percent);
|
||||
IntakeL.spin(forward);
|
||||
IntakeR.spin(forward);
|
||||
}
|
||||
// only tell the right drive motor to spin if the values are not in the deadband range
|
||||
|
||||
// check the ButtonR1/ButtonR2 status to control Intake
|
||||
/*if (Controller1.ButtonR1.pressing()) {
|
||||
IntakeR.spin(forward);
|
||||
IntakeL.spin(forward);
|
||||
Controller1RightShoulderControlMotorsStopped = false;
|
||||
} else if (Controller1.ButtonR2.pressing()) {
|
||||
IntakeR.spin(reverse);
|
||||
IntakeL.spin(reverse);
|
||||
Controller1RightShoulderControlMotorsStopped = false;
|
||||
} else if (!Controller1RightShoulderControlMotorsStopped) {
|
||||
IntakeR.stop(hold);
|
||||
IntakeL.stop(hold);
|
||||
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
|
||||
Controller1RightShoulderControlMotorsStopped = true;
|
||||
}*/
|
||||
// check the Right Shoulder Buttons status to control TiltMotor
|
||||
if (Controller1.ButtonR1.pressing()) {
|
||||
TiltMotor.spin(forward);
|
||||
Controller1UpDownButtonsControlMotorsStopped = false;
|
||||
} else if (Controller1.ButtonR2.pressing()) {
|
||||
TiltMotor.spin(reverse);
|
||||
Controller1UpDownButtonsControlMotorsStopped = false;
|
||||
} else if (!Controller1UpDownButtonsControlMotorsStopped){
|
||||
TiltMotor.stop(hold);
|
||||
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
|
||||
Controller1UpDownButtonsControlMotorsStopped = true;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
#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
|
||||
// define variables used for controlling motors based on controller inputs
|
||||
|
||||
// define a task that will handle monitoring inputs from Controller1
|
||||
int rc_auto_loop_callback_Controller1() {
|
||||
// process the controller input every 20 milliseconds
|
||||
// update the motors based on the input values
|
||||
while(true) {
|
||||
// calculate the drivetrain motor velocities from the controller joystick axies
|
||||
// left = Axis3
|
||||
// right = Axis2
|
||||
|
||||
// wait before repeating the process
|
||||
wait(20, msec);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to initialize code/tasks/devices added using tools in VEXcode Text.
|
||||
*
|
||||
* This should be called at the start of your int main function.
|
||||
*/
|
||||
void vexcodeInit( void ) {
|
||||
task rc_auto_loop_task_Controller1(rc_auto_loop_callback_Controller1);
|
||||
}
|
@ -0,0 +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}
|
@ -0,0 +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)
|
Loading…
Reference in New Issue