I’m having a problem with Vex V5 Pro saving my code which is organized in namespaces. Ex: I tried to edit this file and it did not save my changes File:
#include <cmath>
using namespace ButtonControls;
using namespace vex;
using namespace Odometry;
namespace Auton{
inline namespace AutonFunctions{
void old_Drive(float distance, float velocity, directionType direction = fwd, bool UsesInchesSystem = true) {
if (UsesInchesSystem) {
distance = distance / 0.02181661564;
}
double PastPositionLeft = LeftEncoderY.position(degrees);
double PastPositionRight = RightEncoderY.position(degrees);
LF.spin(direction, velocity, velocityUnits::rpm);
LR.spin(direction, velocity, velocityUnits::rpm);
RF.spin(direction, velocity, velocityUnits::rpm);
RR.spin(direction, velocity, velocityUnits::rpm);
bool Continue = true;
LeftEncoderY.setPosition(0, degrees);
RightEncoderY.setPosition(0, degrees);
while (Continue) {
if (direction == fwd) {
if ((LeftEncoderY.position(degrees) > (distance)) && ((RightEncoderY.position(degrees)/* * -1 */) > (distance))) {
Continue = false;
}
}
else {
if ((LeftEncoderY.position(degrees) < (-distance)) &&
((RightEncoderY.position(degrees) /* *-1*/) < (-distance))) {
Continue = false;
}
}
/*
double m =((1-LeftEncoderY.position(degrees)/distance)+(1-RightEncoderY.position(degrees)/distance))/2;
if (m<0.7){
m = 0.7;
}
LF.spin(direction,velocity*m,velocityUnits::rpm);
LR.spin(direction,velocity*((1-LeftEncoderY.position(degrees)/distance)+(1-RightEncoderY.position(degrees)/distance))/2,velocityUnits::rpm);
RF.spin(direction,velocity*((1-LeftEncoderY.position(degrees)/distance)+(1-RightEncoderY.position(degrees)/distance))/2,velocityUnits::rpm);
RR.spin(direction,velocity*((1-LeftEncoderY.position(degrees)/distance)+(1-RightEncoderY.position(degrees)/distance))/2,velocityUnits::rpm);
*/
}
ButtonControls::stopallmotors(hold);
}
void old_Turn(bool Right,double degreesofturn,double speedofturn = 67,double rangeoferror = 1){
double multiplier = 1;
if(Right == false){
multiplier = -1;
}
if (degreesofturn <= 0){
degreesofturn = degreesofturn *-1;
multiplier = multiplier * -1;
}
Inertial1.resetHeading();
speedofturn = multiplier*speedofturn;
LF.spin(forward,speedofturn,percentUnits::pct);
LR.spin(fwd,speedofturn,percent);
RF.spin(reverse,speedofturn,percentUnits::pct);
RR.spin(reverse, speedofturn, percentUnits::pct); // adkdasldkjasdlakdkjsaldsklsakdjaldjasdjadjadjadjkadjawdjlkawdlkjawdlkadjkadjkaldADADDADADADA
double degminus5 = degreesofturn-rangeoferror;
double degplus5 = degreesofturn+rangeoferror;
while(!(degminus5 <= Inertial1.heading(deg) && degplus5 >= Inertial1.heading(deg))){
task::sleep(5);
}
LF.stop();
LR.stop();
RF.stop();
RR.stop();
}
}
//Settings
double turnKp = 0.3;
double turnKd = 3.5;
double turnKi = 1;
double turnKs = 1;
void turnToHeadingDeg(double desiredheading){
int error = 0;
int prevError = 0;
int derivative = 0;
bool enableTurnPID = true;
bool Right = true;
directionType leftdirection;
directionType rightdirection;
if (desiredheading <0){
desiredheading = 360 + desiredheading;
}
if(desiredheading >180){
Right = false;
Controller1.rumble("...........");
}
if (Right){leftdirection = forward;rightdirection = reverse;}else{leftdirection = reverse;rightdirection = forward;}
while (enableTurnPID){
// f
if(Right == true){
error = desiredheading-Odometry::CalulatedHeadingDeg ;
Brain.Screen.print("RIGHT IS THE WATY");
turnKd = 0.5;
turnKp = 0.6;
// ysjlkfjkxfjklsfkjlsd
}
else{
error = Odometry::CalulatedHeadingDeg-desiredheading;
turnKp = 0.3;
turnKd = 3.5;
}
derivative = prevError -error;
double motorPower = ( error * turnKp + derivative*turnKd);
motorPower = motorPower ;
motorPower = keeplessthan(motorPower, motorPower, 5);
LF.spin(leftdirection,motorPower,percent);
LR.spin(leftdirection,motorPower,percent);
RF.spin(rightdirection,motorPower,percent);
RR.spin(rightdirection,motorPower,percent);
Brain.Screen.setCursor(3,1);
Brain.Screen.print("Power:");
Brain.Screen.print(motorPower);
prevError = error;
if(Right == true){
if((desiredheading) >=Odometry::CalulatedHeadingDeg && (desiredheading-2) <=Odometry::CalulatedHeadingDeg ){
enableTurnPID = false;
}
}
else{
if((desiredheading+2) >=Odometry::CalulatedHeadingDeg && (desiredheading) <=Odometry::CalulatedHeadingDeg ){
enableTurnPID = false;
}
}
task::sleep(20);
}
LF.stop(hold);
LR.stop(hold);
RF.stop(hold);
RR.stop(hold);
}
void TurntoPoint(double x, double y ){
double desiredheading = Odometry::getDesiredHeadingforRotate(Odometry::xPos,Odometry::Main::yPos,x,y);
if(desiredheading<0){
desiredheading = CalulatedHeadingDeg;
}
turnToHeadingDeg(desiredheading);
}
double calculatedistance(double x0,double x1,double y0,double y1){
double d = sqrt(
( (x1-x0)*(x1-x0)) + ((y1-y0)*(y1-y0))
);
return d;
}
double EncoderToIn = 0.02396644697;
// Drive Pd Settings
double kP =1.9;
double kD = 0.45;
void DriveToPoint(double x1,double y1){
TurntoPoint(x1, y1);
double distance = calculatedistance(xPos,x1, yPos, y1);
int startingLeftValue = LeftEncoderY.position(deg);
int startingRightValue = RightEncoderY.position(deg);
bool enablePD = true;
double Lerror = 0;
double LprevError = 0;
double Lderivative = 0;
double Rerror = 0;
double RprevError = 0;
double Rderivative = 0;
if (distance < 0){
distance = distance * -1;
}
while (enablePD){
double Labsoluteposition = (LeftEncoderY.position(deg) - startingLeftValue)*0.02396644697*0.99009901;
Lerror = Labsoluteposition - distance;
Lerror = Lerror * -1;
Lderivative = Lerror - LprevError;
double LmotorPower = (Lerror *kP + Lderivative*kD);
double Rabsoluteposition =( RightEncoderY.position(deg) - startingRightValue) * 0.02396644697*0.99009901;
Rerror = Rabsoluteposition - distance;
Rerror = Rerror * -1;
Rderivative = Rerror - RprevError;
double RmotorPower = (Rerror * kP + Rderivative * kD);
Brain.Screen.setCursor(7, 1);
Brain.Screen.print(distance);
if (distance < 0) {
if (Labsoluteposition < distance) {
LmotorPower = 0;
}
}
else {
if (Labsoluteposition > distance) {
LmotorPower = 0;
}
}
if (distance < 0) {
if (Rabsoluteposition < distance) {
RmotorPower = 0;
}
}
else {
if (Rabsoluteposition > distance) {
RmotorPower = 0;
}
}
if (distance < 0) {
if ((Rabsoluteposition < distance) && (Labsoluteposition < distance)) {
enablePD = false;
}
}
else {
if (Rabsoluteposition > distance && (Labsoluteposition > distance)) {
enablePD = false;
}
}
LF.spin(forward,LmotorPower,percent);
LR.spin(forward,LmotorPower,percent);
RF.spin(forward,RmotorPower,percent);
RR.spin(forward,RmotorPower,percent);
LprevError = Lerror;RprevError = Rerror;
task::sleep(20);
}
LF.stop(hold);
LR.stop(hold);
RF.stop(hold);
RR.stop(hold);
}
}```
This file is tied to all of my auton files Example File (LeftSpin):```#include "AutonFunctions.h"
#include "robot-config.h" // adlkjsajdsajdljkadljkaskldakldlasjkdj
using namespace Auton::AutonFunctions;
using namespace ButtonControls::ColorSpinnerFunctions;
using namespace ButtonControls::ShooterFunctions;
using namespace ButtonControls::IntakeFunctions;
using namespace ButtonControls;
namespace Auton{
namespace Autons{
void LeftSpin(){
LF.spin(reverse,40,percent);
LR.spin(reverse,40,percent);
RF.spin(reverse,40,percent);
RR.spin(reverse,40,percent);
if(ButtonControls::IsBlue == true){
SpinUntilBlue();
}
else{
SpinUntilRed();
}
ButtonControls::stopallmotors();
}
}
}```
ends at my main file:```#include "vex.h" // Includes the vex libray
#include "NameSpaceGlobal.h" // Includes My Library
using namespace vex; // Exports All of the functions and types in namespace "vex"
using namespace DisplayControls; // Exports All of the functions and types in namespace "DisplayControls"
using namespace UserControl;// Exports All of the functions and types in namespace "UserControl"
using namespace Odometry;
using namespace Auton;
competition Competition; // Delcares the Competion
int main() { // The Main Function
Inertial1.calibrate();
while(Inertial1.isCalibrating()){
wait(15, msec);
}
Odometry::Set::setInit();
thread thread1(Odometry::Orientation::OrientationInit);
thread thread2(Odometry::odomInit);
ColorSensor.setLight(ledState::on);
/*
Competition.drivercontrol(UserControl::usercontrol); // Delcares User Control
Competition.autonomous(Autcon::dautonomous);
*/
Auton::Autons::TestOdom();
DisplayControls::DisplayMain(); // Displays Things on the screen
}
The two fixes that I found for it not updating my code is to make a error in the main file and in the file I’m trying to save. Then build, Remove Error from the main file, Build, Remove error from the file I’m trying to save, Download. I also found that if I use another code editor such as Visual studio and then downloading it with vexcode v5 pro.
Any Ideas on more convenient and less time consuming solutions?