When defining a function you need that bracket, the error is somewhere else. There’s likely something in the loop messing up the definition (ie missing an end bracket).
The second statement, int main (); is typically used for functions defined in another file but is used in this one.
#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.
// ........................................................................
// while (1){
Drivetrain.drive(forward);
if(Controller1.ButtonL1.pressing()){
;
Arm.spin(forward);
}
if(Controller1.ButtonL2.pressing()){
;
Arm.spin(reverse);
}
if(Controller1.ButtonX.pressing()){
;
Claw.spin(forward);
}
if(Controller1.ButtonY.pressing()){
;
Claw.spin(reverse);
}
// ........................................................................
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);
}
}
Also please note that you are telling your drivetrain to constantly move forward.
Finally if none of the buttons for a motor are being pressed, you probably want them to stop. Just add another if for if none of them are being pressed, stop.
There are several issues that appear in your code.
First one is semicolon after main, it should be int main() {
The second is you may need to tell motors desired spin velocity.
Third, you need to tell motors to stop when no buttons is pressed.
else if( Controller1.ButtonL1.pressing() )
{
Arm.spin(forward, 70, pct); // at 70%
}
else if( Controller1.ButtonL2.pressing() )
{
Arm.spin(reverse, 50, pct); // at 50%
}
else
{
Arm.stop(hold); // hold arm in place
}
For velocity every motor is preset to (I think) 40% but it can be changed with motor.velocity, so you don’t necessarily need to list power jn each spin statement
This is a very good observation that you could independently set motor velocity without starting the motor. I didn’t know it was preset to 40%.
I was trying to show that motor stop command was missing and that you don’t have to use same motor power when arm goes up and down. Gravity assists motor going down and motor has to overcome gravity going up.
If rubber bands are not assisting the arm to stay in high position, then you need to hold it when no buttons is pressed.