Three wire ports not working during autonomous


#1

During autonomous, three wire sensors almost never output correctly. what


#2

You should post your code so the community can better help you.


#3

Here is basically everything that matters here:

//In robot-config.h
vex::sonar sonar = vex::sonar(Brain.ThreeWirePort.C);

//In main.cpp
void auton(void) {
    Brain.Screen.printAt(100,100,"%d",sonar.distance(vex::distanceUnits::mm));
}

Competition.autonomous(auton);

It prints 0, when it should print -1 or some other number.

also, @jpearman, do you know if there is an issue with auto, threads, and threewireports?

Edit: trying not to confuse people


#4

you cant use auto because its a keyword in c++


#5

paraphrasing, thats not the actual function name


#6

you mean using three wire ports during autonomous ? No problems as far as I know.


#7

I just tested this, no problems at all.

vex::sonar       Sonar( Brain.ThreeWirePort.C );

void autonomous( void ) {
    while(1) {
      Brain.Screen.printAt( 10, 40, "Sonar %.2f", Sonar.distance(distanceUnits::mm) );
      this_thread::sleep_for(20);
    }
}

remember that the Sonar.distance method returns a double, that may be your issue.