I have recently ran into a problem with Robot Mesh. I am trying to make a toggle system for an intake which is not working. The toggle if facilitated by the variable “b”. Does anyone have any suggestions?
Here is my program:
// VEX V5 C++ Project with Competition Template
#include "vex.h"
using namespace vex;
//#region config_globals
vex::brain Brain;
vex::motor motorL(vex::PORT12, vex::gearSetting::ratio18_1, false);
vex::motor motorS(vex::PORT9, vex::gearSetting::ratio18_1, false);
vex::motor motorR(vex::PORT10, vex::gearSetting::ratio18_1, true);
vex::motor motorUD(vex::PORT3, vex::gearSetting::ratio18_1, true);
vex::motor motorUD2(vex::PORT4, vex::gearSetting::ratio18_1, true);
vex::motor motorI(vex::PORT6, vex::gearSetting::ratio18_1, true);
vex::motor motorCUD(vex::PORT7, vex::gearSetting::ratio18_1, true);
vex::controller Controller1(vex::controllerType::primary);
int b = 0;
//#endregion config_globals
// Creates a competition object that allows access to Competition methods.
vex::competition Competition;
void pre_auton() {
// All activities that occur before competition start
}
void autonomous() {
// Autonomus
Brain.Screen.setFillColor(color::green);
Brain.Screen.render();
}
void drivercontrol() {
// Driver Control
while (true) {
//Drive
motorL.spin(vex::directionType::fwd, Controller1.Axis2.value()/1.4 + Controller1.Axis4.value()/2, vex::velocityUnits::pct);
motorR.spin(vex::directionType::fwd, Controller1.Axis2.value()/1.4 + Controller1.Axis4.value()/2 * -1, vex::velocityUnits::pct);
//Move ramp up and down
if (Controller1.ButtonR1.pressing()) {
motorUD.spin(vex::directionType::fwd, 255, vex::velocityUnits::pct);
motorUD2.spin(vex::directionType::fwd, 255, vex::velocityUnits::pct);
}
else if (Controller1.ButtonR2.pressing()) {
motorUD.spin(vex::directionType::rev, 255, vex::velocityUnits::pct);
motorUD2.spin(vex::directionType::rev, 255, vex::velocityUnits::pct);
}
else if (not Controller1.ButtonR2.pressing() or not Controller1.ButtonR1.pressing()) {
motorUD.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
motorUD2.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
}
//Intake motor toggle
if (Controller1.ButtonUp.pressing()) {
if (b = 0) {
b = 1;
}
else if (b = 1) {
b = 0;
}
}
else if (Controller1.ButtonDown.pressing()) {
if (b = 0) {
b = -1;
}
else if (b = -1) {
b = 0;
}
}
//Intake Move
if (b = 1) {
motorI.spin(vex::directionType::fwd, 255, vex::velocityUnits::pct);
}
else if (b = -1) {
motorI.spin(vex::directionType::rev, 255, vex::velocityUnits::pct);
}
else if (b = 0) {
motorI.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
}
//Move claw up and down
if (Controller1.ButtonL1.pressing()) {
motorUD.spin(vex::directionType::fwd, 255, vex::velocityUnits::pct);
}
else if (Controller1.ButtonL2.pressing()) {
motorUD.spin(vex::directionType::rev, 255, vex::velocityUnits::pct);
}
else if (not Controller1.ButtonL2.pressing() or not Controller1.ButtonL1.pressing()) {
motorUD.spin(vex::directionType::fwd, 0, vex::velocityUnits::pct);
}
//Strafe
if (Controller1.Axis1.value() > -25 or Controller1.Axis1.value() < 25) {
motorS.spin(vex::directionType::fwd, Controller1.Axis1.value(), vex::velocityUnits::pct);
//Screen drawing
Brain.Screen.clearLine(1, color::blue);
Brain.Screen.clearLine(2,color::red);
Brain.Screen.clearLine(3,color::blue);
Brain.Screen.clearLine(4,color::blue);
Brain.Screen.clearLine(5,color::red);
Brain.Screen.clearLine(6,color::red);
Brain.Screen.clearLine(7,color::blue);
Brain.Screen.clearLine(8,color::blue);
Brain.Screen.clearLine(9,color::red);
Brain.Screen.clearLine(10,color::red);
Brain.Screen.clearLine(11,color::blue);
Brain.Screen.clearLine(12,color::blue);
Brain.Screen.setCursor(0,1);
Brain.Screen.print(b);
Brain.Screen.render(); //Prevent flickering, b/c it is annoying and weird looking.
}
}
}
int main() {
// Do not adjust the lines below
// Set up (but don't start) callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(drivercontrol);
// Run the pre-autonomous function.
pre_auton();
// Robot Mesh Studio runtime continues to run until all threads and
// competition callbacks are finished.
}