Hello, I am making a custom drive train class for my robot this year and some why every time I try to make a motor spin or something like that I get the 034143C0 memory error.
I have tried many solution and some why none of them are working.
here the code:
main.cpp:
Summary
#include "sys/_intsup.h"
#include "sys/_stdint.h"
#include "vex.h"
#include "DRIVE_TRAIN.h"
#include "vex_drivetrain.h"
#include "vex_global.h"
#include <string>
using namespace vex;
competition Competition;
bool IsAuto = false;
DRIVE_TRAIN Drive_train{0.008,0,0,PORT1,PORT2,PORT3,PORT4,PORT5,PORT6,PORT7,PORT8,PORT9};
const char * Auto1() {
Brain.Screen.setCursor(1,1);
Brain.Screen.clearScreen();
//autonomus[selected].c_str();
//Drive_train.Test();
Drive_train.Test();
Brain.Screen.print("hi");
return "Done";
}
int whenStarted1() {
Drive_train.Init();
BumperA.pressed(PressDetect);
return 0;
}
void VEXcode_driver_task() {
// Start the driver control tasks....
vex::task drive0(ondriver_drivercontrol_0);
while(Competition.isDriverControl() && Competition.isEnabled()) {this_thread::sleep_for(10);}
drive0.stop();
return;
}
void VEXcode_auton_task() {
// Start the auton control tasks....
vex::task autotest(SelectAuto);
while(Competition.isAutonomous() && Competition.isEnabled()) {this_thread::sleep_for(10);}
autotest.stop();
return;
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vex::competition::bStopTasksBetweenModes = false;
Competition.autonomous(VEXcode_auton_task);
Competition.drivercontrol(VEXcode_driver_task);
vexcodeInit();
whenStarted1();
}
DRIVE_TRAIN.cpp:
Summary
#include "math.h"
#include "stdio.h"
#include "sys/_stdint.h"
#include "time.h"
#include "vex.h"
#include "vex_global.h"
#include "vex_imu.h"
#include "MiniPID.h"
#include "vex_motor.h"
#include "vex_motorgroup.h"
#include "vex_task.h"
#include "DRIVE_TRAIN.h"
using namespace vex;
DRIVE_TRAIN::DRIVE_TRAIN(double P,double I,double D,int32_t PORT_FR,int32_t PORT_FL,int32_t PORT_RR,int32_t PORT_RL,int32_t PORT_ML,int32_t PORT_MR,int32_t PORT_CAT,int32_t PORT_INT,int32_t PORT_INERTIAL): DRIVE_PID(P,I,D), TURN_PID(P,I,D), MOTOR_FR(PORT_FR, ratio6_1, true), MOTOR_FL(PORT_FL, ratio6_1, false),MOTOR_RR(PORT_RR, ratio6_1, false),MOTOR_RL(PORT_RL),MOTOR_MR(PORT_MR, ratio6_1, false),MOTOR_ML(PORT_ML,ratio6_1, false),MOTOR_CAT(PORT_CAT,ratio6_1, false),MOTOR_INT(PORT_INT,ratio6_1, false),INERTIAL(PORT_INERTIAL),LEFT_SIDE(MOTOR_FL,MOTOR_RL,MOTOR_ML),RIGHT_SIDE(MOTOR_FR,MOTOR_RR,MOTOR_MR)
{
this->P = P;
this->I = I;
this->D = D;
}
void DRIVE_TRAIN::Init(){
/*DRIVE_PID=MiniPID(P,I,D);
TURN_PID=MiniPID(P,I,D);
MOTOR_FR = motor(PORT_FR, ratio6_1, true);
MOTOR_FL = motor(PORT_FL, ratio6_1, false);
MOTOR_RR = motor(PORT_RR, ratio6_1, false);
MOTOR_RL = motor(PORT_RL, ratio6_1, true);
MOTOR_ML = motor(PORT_ML, ratio6_1, true);
MOTOR_MR = motor(PORT_MR, ratio6_1, false);
MOTOR_CAT = motor(PORT_CAT, ratio6_1, false);
MOTOR_INT = motor(PORT_INT, ratio6_1, false);
INERTIAL = inertial(PORT_INERTIAL);*/
this->RIGHT_SIDE = motor_group(MOTOR_RR,MOTOR_FR,MOTOR_MR);
this->LEFT_SIDE = motor_group(MOTOR_RL,MOTOR_FL,MOTOR_MR);
//Controller1 = controller(primary);
OUTPUT_DRIVE;
OUTPUT_TURN;
DESIRED_DRIVE = 0;
DESIRED_TURN = 0;
SWITCH = false;
}
void DRIVE_TRAIN::Pid_loop(){
while (1){
if (PID_ENABLED == true){
if (SWITCH == true){
this->RIGHT_SIDE.setPosition(0,degrees);
this->LEFT_SIDE.setPosition(0,degrees);
SWITCH = false;
}
int DRIVE_AVERAGE = (RIGHT_SIDE.position(degrees)+RIGHT_SIDE.position(degrees))/2;
int TURN_AVERAGE = Get_angle(); //(RIGHT_SIDE.position(degrees)-RIGHT_SIDE.position(degrees));
OUTPUT_DRIVE = DRIVE_PID.getOutput(DRIVE_AVERAGE,DESIRED_DRIVE);
OUTPUT_TURN = TURN_PID.getOutput(TURN_AVERAGE,DESIRED_TURN);
this->RIGHT_SIDE.spin(forward,OUTPUT_DRIVE+OUTPUT_TURN,voltageUnits::volt);
this->LEFT_SIDE.spin(forward,OUTPUT_DRIVE-OUTPUT_TURN,voltageUnits::volt);
}
}
}
void DRIVE_TRAIN::Start_drive(){
while (true) {
if (DRIVE_ENABLED){
int LEFT_SIDE_SPEED = Controller1.Axis3.position();
int RIGHT_SIDE_SPEED = Controller1.Axis2.position();
RIGHT_SIDE.setVelocity(RIGHT_SIDE_SPEED, percent);
RIGHT_SIDE.spin(forward);
LEFT_SIDE.setVelocity(LEFT_SIDE_SPEED, percent);
LEFT_SIDE.spin(forward);
} else {
LEFT_SIDE.stop();
RIGHT_SIDE.stop();
}
}
}
void DRIVE_TRAIN::Drive_for(double DEGREE){
DESIRED_DRIVE = DEGREE;
SWITCH = true; // ?
}
void DRIVE_TRAIN::Turn_for(double ANGLE){
DESIRED_TURN = ANGLE; //* 14.65;
SWITCH = true;
}
double DRIVE_TRAIN::Get_angle(){
return INERTIAL.angle();
}
int DRIVE_TRAIN::Test(){
this->RIGHT_SIDE.spinFor(forward, 900.0, degrees, true);
return 1;
}
Thank you for helping if you do help.