I need help to do autonomous but with voids

So I got to program the autonomous and I want to use voids for it. How would I put it in the main program?
My void:
void goForward(){
LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
}
void goBackward(){
LF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
}
void goRight(){
LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
}
void goLeft(){
LF.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
LB.spin(vex::directionType::rev,100,vex::velocityUnits::pct);
RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
}
and in the main program(which is what im trynna make work):
void autonomous();{
void goForward();
}
when I try to add a time value to the void it shows it as an error

your functions do not have parameter of time.

when I try to add a time parameter it says “variable has incomplete type void”

show us how you add a time parameter. Your functions do not even have time parameter defined.

in your autonomous, call the void with:
goForward();

you are getting the error by putting void in front of the call, which the compiler wants to see completed with { // void content }

1 Like

ex: void goForward(20);

your function do not accept parameter.

use wait(50, msec) after your function.

goForward();
wait(50, msec);

I may not have the syntax exactly right but this is the general idea:

// You want to pass in a parameter to your function
void goForward(int t){
  LF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
  RF.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
  LB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
  RB.spin(vex::directionType::fwd,100,vex::velocityUnits::pct);
  // Now use the parameter
  wait(t, msec);
  // Stop all the motors so it will do the next step.
  LF.stop();
  RF.stop();
  LB.stop();
  RB.stop();
}

int main() {
  goForward(2000); // Forward for 2 seconds
  wait(2000, msec); // Wait for 2 seconds
  goForward(3000); // Forward for 3 seconds
}
2 Likes

still says variable has incomplete type void

When you declare a function such as:

void foo() {
wait(2000, msec);
}

Implicitly, it is interpreted as:

void foo(void) {
wait(2000, msec);
return;
}

So when you try to call foo(20), the compiler is telling you that 20 is an int which is not compatible with the void type.

2 Likes

Screen Shot 2019-12-06 at 4.34.58 PM

1 Like

Remove the void in front of void goForward(1000); on line 62. The line should read goForward(1000);

1 Like

There is also an unnecessary ; before the {
Also, is this in the competition template? There should be an autonomous void already waiting for your code.

2 Likes

idk how to put it in competition template

its says use of undeclared identifier, btw I do have the void file attached

The competition template is an example program, and it is found by using the tab on the top of the window. I don’t remember where it is located because I don’t have a computer with vexcode with me at the moment, but it shouldn’t be too hard to find.

please copy and paste all your code and use to enclose your code

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       VEX                                                       */
/*    Created:      Thu Sep 26 2019                                           */
/*    Description:  Competition Template                                      */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

// A global instance of competition
competition Competition;

// 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) {
  // ..........................................................................
  // Insert autonomous user code here.
  // ..........................................................................
}

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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) {
    // 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() {
  // Set up callbacks for autonomous and driver control periods.
  Competition.autonomous(autonomous);
  Competition.drivercontrol(usercontrol);

  // Run the pre-autonomous function.
  pre_auton();

  // Prevent main from exiting with an infinite loop.
  while (true) {
    wait(100, msec);
  }
}
2 Likes

If you are using variables, you can’t have a decimal as the input. I dont know why this is.

There are multiple variable types. Some of them dont do decimal numbers. I believe “float” and “double” are the two variables can you normally using for decimal numbers.

1 Like