Programming Errors Related To '{' C++ Begginer

I need some help with my code (c++), I have errors marked on some of the { .
The 6 lines with errors are: ,with full code below
image






I’m hoping this is a simple thing that I need to change.
Full code below:
Please relpy with help, thanks!

 pragma region VEXcode Generated Robot Configuration

// Make sure all required headers are included.

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

#include <math.h>

#include <string.h>

#include "vex.h"

using namespace vex;

// Brain should be defined by default

brain Brain;

// START V5 MACROS

#define waitUntil(condition) \

do { \

wait(5, msec); \

} while (!(condition))

#define repeat(iterations) \

for (int iterator = 0; iterator < iterations; iterator++)

// END V5 MACROS

// Robot configuration code.

// Robot configuration code.

motor L1 = motor(PORT1, ratio6_1, true);

motor L2 = motor(PORT2, ratio6_1, true);

motor L3 = motor(PORT3, ratio6_1, true);

motor R1 = motor(PORT11, ratio6_1, false);

motor R2 = motor(PORT12, ratio6_1, false);

motor R3 = motor(PORT13, ratio6_1, false);

motor Catapult = motor(PORT10, ratio6_1, true);

controller Controller1 = controller(primary);

motor_group RightDriveSmart = motor_group(R3, R2, R1);

motor_group LeftDriveSmart = motor_group(L3, L2, L1);

drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 40, mm, 1);

// Helper to make playing sounds from the V5 in VEXcode easier and

// keeps the code cleaner by making it clear what is happening.

void playVexcodeSound(const char * soundName) {

printf("VEXPlaySound:%s\n", soundName);

wait(5, msec);

}

// define variable for remote controller enable/disable

bool RemoteControlCodeEnabled = true;

// define variables used for controlling motors based on controller inputs

bool DrivetrainLNeedsToBeStopped_Controller1 = true;

bool DrivetrainRNeedsToBeStopped_Controller1 = true;

// define a task that will handle monitoring inputs from Controller1

int rc_auto_loop_function_Controller1() {

// process the controller input every 20 milliseconds

// update the motors based on the input values

while (true) {

if (RemoteControlCodeEnabled) {

// calculate the drivetrain motor velocities from the controller joystick axies

// left = Axis3 + Axis1

// right = Axis3 - Axis1

int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis1.position();

int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis1.position();

// check if the value is inside of the deadband range

if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {

// check if the left motor has already been stopped

if (DrivetrainLNeedsToBeStopped_Controller1) {

// stop the left drive motor

LeftDriveSmart.stop();

// tell the code that the left motor has been stopped

DrivetrainLNeedsToBeStopped_Controller1 = false;

}

} else {

// reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range

DrivetrainLNeedsToBeStopped_Controller1 = true;

}

// check if the value is inside of the deadband range

if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {

// check if the right motor has already been stopped

if (DrivetrainRNeedsToBeStopped_Controller1) {

// stop the right drive motor

RightDriveSmart.stop();

// tell the code that the right motor has been stopped

DrivetrainRNeedsToBeStopped_Controller1 = false;

}

} else {

// reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range

DrivetrainRNeedsToBeStopped_Controller1 = true;

}

// only tell the left drive motor to spin if the values are not in the deadband range

if (DrivetrainLNeedsToBeStopped_Controller1) {

LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);

LeftDriveSmart.spin(forward);

}

// only tell the right drive motor to spin if the values are not in the deadband range

if (DrivetrainRNeedsToBeStopped_Controller1) {

RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);

RightDriveSmart.spin(forward);

}

}

// wait before repeating the process

wait(20, msec);

}

return 0;

}

task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);

#pragma endregion VEXcode Generated Robot Configuration

// ----------------------------------------------------------------------------

//

// Project:

// Author:

// Created:

// Configuration:

//

// ----------------------------------------------------------------------------

// Include the V5 Library

#include "vex.h"

// Allows for easier use of the VEX Library

using namespace vex;

// Begin project code

void preAutonomous(void) {

// actions to do when the program starts

Brain.Screen.clearScreen();

Brain.Screen.print("pre auton code");

wait(1, seconds);

competition Competition;

bool enableDrivePD = true;

double kP = 0.005;

double kD = 0.0;

double turnkP = 0.07;

double turnkD = 0.0;

int desiredvalue = 200;

int desiredTurnvalue = 0;

int error;

int prevError = 0;

int derivative; //speed

int totalError = 0;

int turnError;

int turnPrevError = 0;

int turnDerivative; //speed

int turnTotalError = 0;

bool resetDriveSensors = false;

bool DriveSensors = true;

int DrivePD() {

while (enableDrivePD) {

if (resetDriveSensors) {

resetDriveSensors = false;

L1.setPosition(0, degrees);

R3.setPosition(0, degrees);

}

int leftMotorpostition = L1.position(degrees);

int rightMotorpostition = R3.position(degrees);

//////////////////////////////////////////////////

///Lateral PID

/////////////////////////////////////////////////

int averageposition = (leftMotorpostition + rightMotorpostition) / 2;

//Potential

error = averageposition - desiredvalue;

//Derivative

derivative = error - prevError;

double motorPower = (error * kP + derivative * kD);

/////////////////////////////////////////////////

///Turning PID

/////////////////////////////////////////////////

int turnDifference = (leftMotorpostition - rightMotorpostition) / 2;

//Potential

turnError = turnDifference - desiredTurnvalue;

//Derivative

turnDerivative = turnError - turnPrevError;

//Integral

turnTotalError += turnError;

double turnMotorPower = (turnError * turnkP + turnDerivative * turnkD);

L1.spin(forward, motorPower + turnMotorPower, voltageUnits::volt);

L2.spin(forward, motorPower + turnMotorPower, voltageUnits::volt);

L3.spin(forward, motorPower + turnMotorPower, voltageUnits::volt);

R1.spin(forward, motorPower - turnMotorPower, voltageUnits::volt);

R2.spin(forward, motorPower - turnMotorPower, voltageUnits::volt);

R3.spin(forward, motorPower - turnMotorPower, voltageUnits::volt);

wait(5, msec);

prevError = error;

turnPrevError = turnError;

vex::task::sleep(20);

}

return 1;

}

float myVariable;

}

void autonomous(void) {

Brain.Screen.clearScreen();

Brain.Screen.print("autonomous code");

// place automonous code here

void VEXcode_auton_task() {

///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////

//////////Auton

vex::task First(DrivePD);

bool enableDrivePD = true;

while (enableDrivePD){

resetDriveSensors = true;

int desiredValue = 300;

desiredTurnvalue = 600;

vex::task::sleep(1000);

resetDriveSensors = true;

desiredValue = 300;

desiredTurnvalue = 300;

}

return;

wait(5, msec);

}

}

void userControl(void) {

Brain.Screen.clearScreen();

// place driver control in this while loop

while (true) {

// "when driver control" hat block

int ondriver_drivercontrol_0() {

while (1) {

L1.spin(forward, Controller1.Axis3.position(), volt);

L2.spin(forward, Controller1.Axis3.position(), volt);

L3.spin(forward, Controller1.Axis3.position(), volt);

R1.spin(forward, Controller1.Axis3.position(), volt);

R2.spin(forward, Controller1.Axis3.position(), volt);

R3.spin(forward, Controller1.Axis3.position(), volt);

wait(5, msec);

}

while (Competition.isAutonomous() && Competition.isEnabled()) {

}

return 0;

}

// "when driver control" hat block

int ondriver_drivercontrol_1() {

while (1) {

L1.spin(reverse, Controller1.Axis1.position(), volt);

L2.spin(reverse, Controller1.Axis1.position(), volt);

L3.spin(reverse, Controller1.Axis1.position(), volt);

R1.spin(forward, Controller1.Axis1.position(), volt);

R2.spin(forward, Controller1.Axis1.position(), volt);

R3.spin(forward, Controller1.Axis1.position(), volt);

wait(5, msec);

}

while (Competition.isAutonomous() && Competition.isEnabled()) {

}

return 0;

}

// "when driver control" hat block

int ondriver_drivercontrol_2() {

Brain.Screen.clearScreen();

while (true) {

if (Controller1.ButtonX.pressing()) {

Catapult.spin(forward);

waitUntil(Controller1.ButtonA.pressing());

} else {

Catapult.stop();

}

wait(5, msec);

}

return 0;

}

void VEXcode_driver_task() {

// Start the driver control tasks....

vex::task drive0(ondriver_drivercontrol_0);

vex::task drive1(ondriver_drivercontrol_1);

vex::task drive2(ondriver_drivercontrol_2);

while (Competition.isDriverControl() && Competition.isEnabled()) {

this_thread::sleep_for(10);

}

drive0.stop();

drive1.stop();

return;

}

wait(20, msec);

}

}

int main() {

// create competition instance

competition Competition;

// Set up callbacks for autonomous and driver control periods.

Competition.autonomous(autonomous);

Competition.drivercontrol(userControl);

// Run the pre-autonomous function.

preAutonomous();

// Prevent main from exiting with an infinite loop.

while (true) {

wait(100, msec);

}

} 

Its probably because you declared the functions inside a function(i pasted it into vexcode). I would recommend you fix the indentation to see it easier, and to go on from there.

1 Like

For the first snippet of code (int DrivePd), you forgot to set a closing bracket for the if statement & the while statement.

For the second one, you forgot to the close it yet again.

I’m not quite sure about the third one, since it’s difficult to tell what’s going on without proper indentation. Same for the fourth, fifth, & sixth ones. I highly recommend indenting your code, as it is difficult to help. I hope you get the help you need, though!

1 Like