Hi everyone, I am having an issue with running a motor. I have the port that just burnt out with another one, and the motor is fine. The motor is not spinning to run the intake rollers. I have tried plugging it into another motor, and nothing is working.
Code
// VEX V5 C++ Project
#include <algorithm>
#include <cmath>
#include "vex.h"
// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----
using namespace vex;
// A global instance of competition
competition Competition;
//#region config_globals
vex::motor back_right_motor(vex::PORT1, vex::gearSetting::ratio18_1, true);
vex::motor back_left_motor(vex::PORT10, vex::gearSetting::ratio18_1, false);
vex::motor front_right_motor(vex::PORT11, vex::gearSetting::ratio18_1, true);
vex::motor front_left_motor(vex::PORT20, vex::gearSetting::ratio18_1, false);
vex::motor intake_arm_mover(vex::PORT5, vex::gearSetting::ratio36_1, false);
vex::motor intake_left(vex::PORT12, vex::gearSetting::ratio36_1, false);
vex::motor intake_right(vex::PORT19, vex::gearSetting::ratio36_1, false);
vex::motor tray_mover(vex::PORT16, vex::gearSetting::ratio36_1, false);
vex::controller con(vex::controllerType::primary);
//#endregion config_globals
// 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. */
/*---------------------------------------------------------------------------*/
void autonomous(void) {
//front_left_motor.spin(fwd);
back_left_motor.spin(fwd); //forward);
front_right_motor.spin(fwd);
front_left_motor.spin(fwd);
back_right_motor.spin(fwd);
wait(2, seconds);
back_left_motor.spin(reverse);
front_right_motor.spin(reverse);
front_left_motor.spin(reverse);
back_right_motor.spin(reverse);
wait(1.25,seconds);
tray_mover.spin(fwd);
wait(0.75,seconds);
intake_left.spin(reverse);
intake_right.spin(reverse);
tray_mover.spin(fwd);
wait(1,seconds);
tray_mover.spin(reverse);
wait(2,seconds);
}
/*---------------------------------------------------------------------------*/
/* */
/* 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. */
/*---------------------------------------------------------------------------*/
void usercontrol(void) {
// User control code here, inside the loop
while (1) {
//Setting the speed of the intake rollers and the arms holding the intake rollers
while(true) {
int intakeleftSpeedPCT = 100;
int intakerightSpeedPCT = 100;
int intakearmSpeedPCT = 75;
int traymoverSpeedPCT = 25;
if(con.ButtonL1.pressing()) {
intake_left.spin(directionType::fwd, intakeleftSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonL2.pressing()) {
intake_left.spin(directionType::rev,intakeleftSpeedPCT, velocityUnits::pct);
}
else {
intake_left.stop(brakeType::brake);
}
if(con.ButtonL1.pressing()) {
intake_right.spin(directionType::rev, intakerightSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonL2.pressing()) {
intake_right.spin(directionType::fwd,intakerightSpeedPCT, velocityUnits::pct);
}
else {
intake_right.stop(brakeType::brake);
}
if(con.ButtonUp.pressing()) {
intake_arm_mover.spin(directionType::fwd, intakearmSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonDown.pressing()) {
intake_arm_mover.spin(directionType::rev,intakearmSpeedPCT, velocityUnits::pct);
}
else {
intake_arm_mover.stop(brakeType::brake);
}
if(con.ButtonLeft.pressing()) {
tray_mover.spin(directionType::fwd, traymoverSpeedPCT, velocityUnits::pct);
}
else if (con.ButtonRight.pressing()) {
tray_mover.spin(directionType::rev,traymoverSpeedPCT, velocityUnits::pct);
}
else {
tray_mover.stop(brakeType::brake);
}
//Get the raw sums of the X and Y joystick axes
double front_left = (double)(con.Axis3.position(pct) + con.Axis4.position(pct));
double back_left = (double)(con.Axis3.position(pct) - con.Axis4.position(pct));
double front_right = (double)(con.Axis3.position(pct) - con.Axis4.position(pct));
double back_right = (double)(con.Axis3.position(pct) + con.Axis4.position(pct));
//Find the largest possible sum of X and Y
double max_raw_sum = (double)(abs(con.Axis3.position(pct)) + abs(con.Axis4.position(pct)));
//Find the largest joystick value
double max_XYstick_value = (double)(std::max(abs(con.Axis3.position(pct)),abs(con.Axis4.position(pct))));
//The largest sum will be scaled down to the largest joystick value, and the others will be
//scaled by the same amount to preserve directionality
if (max_raw_sum != 0) {
front_left = front_left / max_raw_sum * max_XYstick_value;
back_left = back_left / max_raw_sum * max_XYstick_value;
front_right = front_right / max_raw_sum * max_XYstick_value;
back_right = back_right / max_raw_sum * max_XYstick_value;
}
//Now to consider rotation
//Naively add the rotational axis
front_left = front_left + con.Axis1.position(pct);
back_left = back_left + con.Axis1.position(pct);
front_right = front_right - con.Axis1.position(pct);
back_right = back_right - con.Axis1.position(pct);
//What is the largest sum, or is 100 larger?
max_raw_sum = std::max(std::abs(front_left),std::max(std::abs(back_left),std::max(std::abs(front_right),std::max(std::abs(back_right),100.0))));
//Scale everything down by the factor that makes the largest only 100, if it was over
front_left = front_left / max_raw_sum * 100.0;
back_left = back_left / max_raw_sum * 100.0;
front_right = front_right / max_raw_sum * 100.0;
back_right = back_right / max_raw_sum * 100.0;
//Write the manipulated values out to the motors
front_left_motor.spin(fwd,front_left, velocityUnits::pct);
back_left_motor.spin(fwd,back_left, velocityUnits::pct);
front_right_motor.spin(fwd,front_right,velocityUnits::pct);
back_right_motor.spin(fwd,back_right, velocityUnits::pct);
}
}
// 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.
// ........................................................................
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() {
// Run the pre-autonomous function.
pre_auton();
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
//autonomous();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}