VEX Configeration file returns "In included file expected name space name"

Hello i get the error “In included file expected name space name”

1 Like

In that file type using namespace vex

1 Like

Here is my code:

ROBOSHEEN-config.h:

using namespace vex;

extern vex::brain Brain;

/**
 * Used to initialize code/tasks/devices added using tools in VEXcode Text.
 *
 * This should be called at the start of your int main function.
 */
void vexcodeInit(void);

ROBOSHEEN.h

#include "ROBOSHEEN-config.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "v5.h"
#include "v5_vcs.h"

using namespace vex;


#define waitUntil(condition)                                                   \
  do {                                                                         \
    wait(5, msec);                                                             \
  } while (!(condition))

#define repeat(iterations)                                                     \
  for (int iterator = 0; iterator < iterations; iterator++)

  double sgn(double number);

void close_claw();

void setLeftPower(int power);
void setRightPower(int power);

void setDrivePower(int left, int right);
void driveStraight(int distance, int power);

void printLineTrackerValue();

// if pass 50, means 50% power
void driveForwardByVelocity(double velocity, int power);

bool isZeroValues();

void see_light_stop(double velocityl, double velocityr);

void hit_wall(double velocity_left, double velocity_right, int sleep_time);

void open_claw();

void see_dark_stop(double velocityl, double velocityr);
void back_see_light_stop(double velocityl, double velocityr);

void back_see_dark_stop(double velocityl, double velocityr);
//trun right: autoTurn(100), slower Turn(100, 30)
void turn_right(int distance, int power) ;

main.cpp

#include "ROBOSHEEN.h"

using namespace vex;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  setDrivePower(50, 50);
  driveStraight(720, 50); 

  //setHDrivePower(50);
  //HDrive(360, 50);

  driveStraight(-720, 50);

  //HDrive(-360, 50);

}

ROBOSHEEN-config.cpp:

#include "ROBOSHEEN.h"
#include <iostream>

#include <vex_triport.h>
#include <cmath>
using namespace vex;

// A global instance of brain used for printing to the V5 brain screen
brain brain1;
vex::motor ClawMotor = vex::motor(vex::PORT3);

vex::motor LtMotorF = vex::motor(vex::PORT7);
vex::motor RtMotorF = vex::motor(vex::PORT16);
vex::motor LtMotorB = vex::motor(vex::PORT2);
vex::motor RtMotorB = vex::motor(vex::PORT14);
vex::motor HMotor = vex::motor (vex::PORT4);
vex::motor Motor1 = vex::motor(vex::PORT6, true);
vex::motor Motor2 = vex::motor(vex::PORT19, true);
vex::controller Controller1 = vex::controller();

motor_group LeftMotor (LtMotorB,LtMotorF);
motor_group RightMotor(RtMotorB,RtMotorF);

line LineTrackerL = line(Brain.ThreeWirePort.A);
line LineTrackerM = line(Brain.ThreeWirePort.B);
line LineTrackerR = line(Brain.ThreeWirePort.C);

void close_claw(){
  ClawMotor.spin(directionType::fwd, 100, velocityUnits::pct);
  task::sleep(750);
  while (ClawMotor.velocity(pct) > 0) {
    ClawMotor.spin(directionType::fwd, 100, velocityUnits::pct);
  }
  ClawMotor.stop(brakeType::hold);
}

void setLeftPower(int power) {
  if (power == 0)
    LeftMotor.stop(vex::brakeType::brake);
   else {
    LeftMotor.spin(vex::directionType::fwd, power, vex::velocityUnits::pct);
  }
}
void setRightPower(int power) {
  if (power == 0)
    RightMotor.stop(vex::brakeType::brake);
   else {
    RightMotor.spin(vex::directionType::rev, power, vex::velocityUnits::pct);
  }
}

void setDrivePower(int left, int right) {
  setLeftPower(left);
  setRightPower(right);
}

void driveStraight(int distance, int power = 100) {
  int direction = sgn(distance);

  // Clear encoder
  LtMotorB.resetRotation();

  while (std::abs(LtMotorB.rotation(vex::rotationUnits::deg)) < std::abs(distance)) {
    setDrivePower(power * direction, power * direction);
  }
  setDrivePower(0, 0);
}

void printLineTrackerValue()
{
  Brain.Screen.clearScreen();
  Brain.Screen.setFont(monoS);
  Brain.Screen.print(Brain.Timer.value());
  while(true)
  {
    task::sleep(3000);
    Brain.Screen.newLine();
    Brain.Screen.print(LineTrackerL.value(analogUnits::range12bit));
    Brain.Screen.newLine();
    Brain.Screen.print(LineTrackerM.value(analogUnits::range12bit));
    Brain.Screen.newLine();
    Brain.Screen.print(LineTrackerR.value(analogUnits::range12bit));
  }
}


// if pass 50, means 50% power
void driveForwardByVelocity(double velocity) {
  LeftMotor.spin(directionType::fwd, velocity, vex::velocityUnits::pct);
  RightMotor.spin(directionType::rev, velocity, vex::velocityUnits::pct);
}

bool isZeroValues() 
{
  if (LineTrackerL.value(analogUnits::range12bit) == 0 &&
      LineTrackerM.value(analogUnits::range12bit) == 0 && 
      LineTrackerR.value(analogUnits::range12bit) == 0 ) {
     return true;
  }
  return false; 
}

void see_light_stop(double velocityl, double velocityr) {
  while (true) {
      //driveForwardByVelocity(40);
      LeftMotor.spin(directionType::fwd, velocityl, velocityUnits::pct);
      RightMotor.spin(directionType::rev, velocityr, velocityUnits::pct);
      
      if (!isZeroValues() &&
          (LineTrackerL.value(analogUnits::range12bit) < 1500 ||
            LineTrackerM.value(analogUnits::range12bit) < 1500 ||
            LineTrackerR.value(analogUnits::range12bit) < 1500) ){
      break;
    }
  }
  LeftMotor.stop(brakeType::hold);
  RightMotor.stop(brakeType::hold);
}

void hit_wall(double velocity_left, double velocity_right, int sleep_time){
    LeftMotor.spin(directionType::rev, velocity_left, velocityUnits::pct);
   RightMotor.spin(directionType::fwd, velocity_right, velocityUnits::pct);
   task::sleep(sleep_time);
   while (LeftMotor.velocity(pct) > 0 && RightMotor.velocity(pct)> 0) {
    LeftMotor.spin(directionType::rev, velocity_left, velocityUnits::pct);
    RightMotor.spin(directionType::fwd, velocity_right, velocityUnits::pct);
  }
  LeftMotor.stop(brakeType::hold);
  RightMotor.stop(brakeType::hold);
}

void open_claw(){
 ClawMotor.spin(directionType::rev, 100, velocityUnits::pct);
  task::sleep(500);
  while (ClawMotor.velocity(pct) > 0) {
    ClawMotor.spin(directionType::rev, 100, velocityUnits::pct);
  }
  ClawMotor.stop(brakeType::hold); 
}

void see_dark_stop(double velocityl, double velocityr) {
  while (true) {
      LeftMotor.spin(directionType::fwd, velocityl, velocityUnits::pct);
      RightMotor.spin(directionType::rev, velocityr, velocityUnits::pct);
      
      if (!isZeroValues() &&
          (LineTrackerL.value(analogUnits::range12bit) > 1500 ||
           LineTrackerM.value(analogUnits::range12bit) > 1500 ||
           LineTrackerR.value(analogUnits::range12bit) > 1500) ){
      break;
    }
  }
  LeftMotor.stop(brakeType::hold);
  RightMotor.stop(brakeType::hold);
}

void back_see_light_stop(double velocityl, double velocityr) {
  while (true) {
      //drive Back
      LeftMotor.spin(directionType::rev, velocityl, velocityUnits::pct);
      RightMotor.spin(directionType::fwd, velocityr, velocityUnits::pct);

      if (!isZeroValues() &&
          (LineTrackerL.value(analogUnits::range12bit) < 1500 ||
            LineTrackerM.value(analogUnits::range12bit) < 1500 ||
            LineTrackerR.value(analogUnits::range12bit) < 1500) ){
      break;
    }
  }
  LeftMotor.stop(brakeType::hold);
  RightMotor.stop(brakeType::hold);
}

void back_see_dark_stop(double velocityl, double velocityr) {
  while (true) {
      //drive Back
      LeftMotor.spin(directionType::rev, velocityl, velocityUnits::pct);
      RightMotor.spin(directionType::fwd, velocityr, velocityUnits::pct);

      if (!isZeroValues() &&
          (LineTrackerL.value(analogUnits::range12bit) > 1500 ||
            LineTrackerM.value(analogUnits::range12bit) > 1500 ||
            LineTrackerR.value(analogUnits::range12bit) > 1500) ){
      break;
    }
  }
  LeftMotor.stop(brakeType::hold);
  RightMotor.stop(brakeType::hold);
}

//trun right: autoTurn(100), slower Turn(100, 30)
void turn_right(int distance, int power) {
  int direction = sgn(distance);

  // Clear encoder
  LeftMotor.resetRotation();
  RightMotor.resetRotation();

  while (std::abs(LeftMotor.rotation(vex::rotationUnits::deg)) <std::abs(distance)) {
    setDrivePower(power * direction, -power * direction);
  }
  setDrivePower(0, 0);
}

//trun left: autoTurn(100), slower Turn(100, 30)
void turn_left(int distance, int power) {
  int direction = sgn(distance);

  // Clear encoder
  LeftMotor.resetRotation();
  RightMotor.resetRotation();

  while (std::abs(LeftMotor.rotation(vex::rotationUnits::deg)) <std::abs(distance)) {
    setDrivePower(-power * direction, power * direction);
  }
  setDrivePower(0, 0);
}

/**
 * Used to initialize code/tasks/devices added using tools in VEXcode Text.
 *
 * This should be called at the start of your int main function.
 */
void vexcodeInit(void) {
  // Nothing to initialize
}
1 Like

I did and it still doesn’t work

1 Like

Thanks for including your complete program! That makes it much easier to debug these sorts of things.

ROBOSHEEN-config.h threw an error on

using namespace vex;

because that file doesn’t know about the vex namespace in the first place, since the files that define that namespace aren’t included.

I added the following two Iines to the top of ROBOSHEEN-config.h:

#include "v5.h"
#include "v5_vcs.h"

and that solved the “expected namespace name” error - although the project still failed to compile due to an error in the driveStraight function.

6 Likes