Defining three wire devices in text

Hey,

I’m having issues defining three wires devices in text.
image

I am defining it like this since the given robot configuration did not work for me previously and I’m not sure how to define bumper switches in particular.

If you know how any help will be appreciated

It’s something like
bumper Bump(Brain.ThreeWirePort.A);

1 Like

When I tried that I got this error

You’d probably need to upload your code so others can figure out the problem

1 Like

We just gave that a try and it did not work for us. We still got the error, How and where do you suggest we put the definition

It should be under your motor declarations, could you upload your code?

vex forum wont let me upload the file because I’m a new user. if you give me an email i can send it to you

You can cut it out of the editor and paste it in your text. just put [code] tags around it. Or three back ticks ` on the beginning and end.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\Andy Lentini                                     */
/*    Created:      Thu Nov 07 2019                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// BumperA              bumper        A               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include <cmath>

using namespace vex;
using namespace std;
motor LF_Drive=motor(PORT12, gearSetting::ratio18_1, true);
motor LB_Drive =motor(PORT20, gearSetting::ratio18_1, true);
motor RB_Drive =motor(PORT1, gearSetting::ratio18_1, false);
motor RF_Drive =motor(PORT6, gearSetting::ratio18_1, false);
motor Lift =motor(PORT2, gearSetting::ratio36_1, false);
motor Tray =motor(PORT5, gearSetting::ratio18_1, true);
motor Right_Intake =motor(PORT10, gearSetting::ratio36_1, true);
motor Left_Intake =motor(PORT8, gearSetting::ratio36_1, true);
bumper LiftBumper = bumper(Brain.ThreeWirePort.A);
controller Controller1;

void DriveTerrainControl() {
  if (Controller1.Axis3.value() > 10) {
    LF_Drive.spin(directionType::fwd, Controller1.Axis3.value(),percentUnits::pct);
    LB_Drive.spin(directionType::fwd, Controller1.Axis3.value(),percentUnits::pct);
  } else if (Controller1.Axis3.value() < -10) {
    LF_Drive.spin(directionType::rev, std::abs(Controller1.Axis3.value()),percentUnits::pct);
    LB_Drive.spin(directionType::rev, std::abs(Controller1.Axis3.value()),percentUnits::pct);
  } else {
    LF_Drive.stop(brakeType::coast);
    LB_Drive.stop(brakeType::coast);
  }

  if (Controller1.Axis2.value() > 10) {
    RF_Drive.spin(directionType::fwd, Controller1.Axis2.value(),percentUnits::pct);
    RB_Drive.spin(directionType::fwd, Controller1.Axis2.value(),percentUnits::pct);
  } else if (Controller1.Axis2.value() < -10) {
    RF_Drive.spin(directionType::rev, std::abs(Controller1.Axis2.value()),percentUnits::pct);
    RB_Drive.spin(directionType::rev, std::abs(Controller1.Axis2.value()),percentUnits::pct);
  } else {
    RF_Drive.stop(brakeType::coast);
    RB_Drive.stop(brakeType::coast);
  }
}

void DriveControl() {
  // Drive Control
  DriveTerrainControl();

  // Brake hold system
  if (Controller1.ButtonA.pressing()) {
    LF_Drive.stop(brakeType::hold);
    LB_Drive.stop(brakeType::hold);
    RF_Drive.stop(brakeType::hold);
    RB_Drive.stop(brakeType::hold);
  } else {
    DriveTerrainControl();
  }
  // Set Speed at half
  if (Controller1.ButtonX.pressing()) {
    if (Controller1.Axis3.value() > 10) {
      LF_Drive.spin(directionType::fwd,(Controller1.Axis3.value() * abs(50) / 100),percentUnits::pct);
      LB_Drive.spin(directionType::fwd,(Controller1.Axis3.value() * abs(50) / 100),percentUnits::pct);
    } 
    else if (Controller1.Axis3.value() < -10) {
      LF_Drive.spin(directionType::rev,(std::abs(Controller1.Axis3.value()) * abs(50) / 100),percentUnits::pct);
      LB_Drive.spin(directionType::rev,(std::abs(Controller1.Axis3.value()) * abs(50) / 100),percentUnits::pct);
    } 
    else {
      LF_Drive.stop(brakeType::coast);
      LB_Drive.stop(brakeType::coast);
    }

    if (Controller1.Axis2.value() > 10) {
      RF_Drive.spin(directionType::fwd,(Controller1.Axis2.value() * abs(50) / 100),percentUnits::pct);
      RB_Drive.spin(directionType::fwd,(Controller1.Axis2.value() * abs(50) / 100),percentUnits::pct);
    }
     else if (Controller1.Axis2.value() < -10) {
      RF_Drive.spin(directionType::rev,(std::abs(Controller1.Axis2.value()) * abs(50) / 100),percentUnits::pct);
      RB_Drive.spin(directionType::rev,(std::abs(Controller1.Axis2.value()) * abs(50) / 100),percentUnits::pct);
    }
     else {
      RF_Drive.stop(brakeType::coast);
      RB_Drive.stop(brakeType::coast);
    }
  } else {
    DriveTerrainControl();
  }
  // Tray control
  if (Controller1.ButtonR1.pressing()) {
    Tray.spin(directionType::fwd, 50, velocityUnits::pct);
  }
   else if (Controller1.ButtonR2.pressing()) {
    Tray.spin(directionType::rev, 100, velocityUnits::pct);
  } 
  else {
    Tray.stop(brakeType::hold);
  }
if(Controller1.ButtonB.pressing()){
  // Lifts the Lift and Tray[]
  if (Controller1.Axis3.value() > 10){
    Lift.spin(directionType::fwd, Controller1.Axis3.value(), percentUnits::pct);
  }
  else if(Controller1.Axis3.value() < -10){
    Lift.spin(directionType::rev, std::abs(Controller1.Axis3.value()), percentUnits::pct);
  }
  else{
    Lift.stop(brakeType::hold);
  }
  // Changes Drive to Arcade Drive
  if (Controller1.Axis2.value() > 10 & Controller1.Axis1.value() > 10) {
    LF_Drive.spin(directionType::fwd,(Controller1.Axis2.value() + Controller1.Axis1.value()) / 2,percentUnits::pct);
    LB_Drive.spin(directionType::fwd,(Controller1.Axis2.value() + Controller1.Axis1.value()) / 2,percentUnits::pct);
    RF_Drive.spin(directionType::fwd,(Controller1.Axis2.value() + Controller1.Axis1.value()) / 2,percentUnits::pct);
    RB_Drive.spin(directionType::fwd,(Controller1.Axis2.value() + Controller1.Axis1.value()) / 2,percentUnits::pct);
  } 
  else if (Controller1.Axis2.value() < -10 &Controller1.Axis1.value() < -10) {
    LF_Drive.spin(directionType::fwd,std::abs((Controller1.Axis2.value() + Controller1.Axis1.value()) / 2),percentUnits::pct);
    LB_Drive.spin(directionType::fwd,std::abs((Controller1.Axis2.value() + Controller1.Axis1.value()) / 2),percentUnits::pct);
    RF_Drive.spin(directionType::fwd,std::abs((Controller1.Axis2.value() + Controller1.Axis1.value()) / 2),percentUnits::pct);
    RB_Drive.spin(directionType::fwd,std::abs((Controller1.Axis2.value() + Controller1.Axis1.value()) / 2),percentUnits::pct);
  } 
  else {
    RF_Drive.stop(brakeType::coast);
    RB_Drive.stop(brakeType::coast);
    LF_Drive.stop(brakeType::coast);
    LB_Drive.stop(brakeType::coast);
  }
}
else{
  DriveTerrainControl();
  Lift.stop(brakeType::hold);
}
  // Intake Control
  if (Controller1.ButtonL1.pressing()) {
    Right_Intake.spin(directionType::fwd, 100, pct);
    Left_Intake.spin(directionType::rev, 100, pct);
  } 
  else if (Controller1.ButtonL2.pressing()) {
    Right_Intake.spin(directionType::rev, 100, pct);
    Left_Intake.spin(directionType::fwd, 100, pct);
  } 
  else {
    Right_Intake.stop(brakeType::hold);
    Left_Intake.stop(brakeType::hold);
  }
}

int main() {

  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  while (1) {

    // Brain.Screen.print("Driver Control Started");
    // Controller1.Screen.print("Driver Control Started");
    // Controller1.rumble(".-.-");
    while (true) {
        DriveControl();
      }
    }
  }

You have an extra #include

The issue is that the build system will not guarantee the order in which instances are created across different source files.

The instance of Brain is defined I’m assuming somewhere else such as robot-config.cpp. That means it may not have been created, and therefore the Brain.ThreeWirePort also not created, when you try to access it in your main.cpp source file. The solution is to either move

bumper LiftBumper = bumper(Brain.ThreeWirePort.A);

into the same file (and placed after) as the Brain instance, or use another instance of the ThreeWirePort that you define in main.cpp like this.

triport  myThreeWirePort(PORT22);
bumper   LiftBumper = bumper( myThreeWirePort.A );

PORT22 is the port number for the internal 3-wire port (which is called a triport in the VEXcode SDK).

If possible, I would use the first solution above
(edit: yes, I realize that although the second solution will work in the case of a bumper switch, it may not work for other sensor types, I need to look into that I guess)

4 Likes

Thank you for all the help!

1 Like