VEXcode V5 Text Help

oh ok

20 characters a

The import feature is not specific to 1.0

import

(Downloaded Two Weeks Ago)

It seems to work now, no more errors thanks so much

np
20 characters
needs even more

what about controller?

vex::controller Controller1;
also sensors
vex::limit LS2 (Brain.ThreeWirePort.B);
also motor group
vex::motor_group AA(RA,LA);

thx, a “while” has an error, but it is one of the computer generated ones from an example, how can I fix it?

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.

what’s the error?
20 characters

expected unqualified id

show the code
20 characters

If you can, please look through the whole thing

/----------------------------------------------------------------------------/
/* /
/
Module: main.cpp /
/
Author: {author} /
/
Created: {date} /
/
Description: V5 project /
/
/
/
----------------------------------------------------------------------------*/
#include “vex.h”

using namespace vex;

// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain Brain;
// A global instance of vex::competition
vex::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 cortex has been powered on and /
/
not every time that the robot is disabled. /
/
---------------------------------------------------------------------------*/

void pre_auton( void ) {
// 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 ) {
// int main() {

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++++
Tank Control
This program instructs your robot to use remote control values to move the robot.

Robot Configuration:
[Smart Port] [Name] [Type] [Description] [Reversed]
Motor Port 1 FrontLeftDr Torque Front Left Drive false
Motor Port 2 FrontRightDr Torque Front Right Drive true
Motor Port 3 BackRightDr Torque Back Right Drive true
Motor Port 4 BackLeftDr Torque Back Left Drive false
Motor Port 6 LeftIntake Normal Sucks cubes for tower true
Motor Port 7 RightIntake Normal Sucks cubes for tower false
Motor Port 8 ChutePush Torque Leans chute false
Motor Port 9 ArmMotor Normal Lifts Slurper true
----------------------------------------------------------------------------------------------------*/
vex::motor FrontLeftDr (vex::PORT1, vex::gearSetting::ratio36_1,false);
vex::motor FrontRightDr (vex::PORT2, vex::gearSetting::ratio36_1,true);
vex::motor BackRightDr (vex::PORT3, vex::gearSetting::ratio36_1,true);
vex::motor BackLeftDr (vex::PORT4, vex::gearSetting::ratio36_1,false);
vex::motor LeftIntake (vex::PORT6, vex::gearSetting::ratio18_1,true);
vex::motor RightIntake (vex::PORT7, vex::gearSetting::ratio18_1,false);
vex::motor ChutePush (vex::PORT8, vex::gearSetting::ratio36_1,false);
vex::motor ArmMotor (vex::PORT9, vex::gearSetting::ratio36_1,true);
vex::controller Controller1;

int main( void );
Brain.Screen.setOrigin(1,1);
//Display that the program has started to the screen.
Brain.Screen.print("");

//Use these variables to set the speed of the arm and claw.
int armSpeedPCT = 100;
int slowClawSpeedPCT = 100;
int chuteSpeedPCT = 70;
Brain.Screen.print("(Subbing to PewDiePie);");
    Brain.Screen.newLine();
    Brain.Screen.newLine();
    Brain.Screen.newLine();
    Brain.Screen.print("(Complete!);");
    Brain.Screen.newLine();
    Brain.Screen.newLine();
    Brain.Screen.newLine();
    Brain.Screen.newLine();
Brain.Screen.print("(Have a great match!);");
    Brain.Screen.newLine();
    Brain.Screen.newLine();
    Brain.Screen.newLine();

//Create an infinite loop so that the program can pull remote control values every iteration.
//This loop causes the program to run forever.
while(1) {
    
    
    //Drive Control 
    //Set the left and right motor to spin forward using the controller Axis values as the velocity value.
    FrontLeftDr.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
    BackLeftDr.spin(vex::directionType::fwd, Controller1.Axis3.value(), vex::velocityUnits::pct);
    FrontRightDr.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
    BackRightDr.spin(vex::directionType::fwd, Controller1.Axis2.value(), vex::velocityUnits::pct);
    
    if(Controller1.ButtonL1.pressing())
        ChutePush.spin(vex::directionType::fwd, chuteSpeedPCT, vex::velocityUnits::pct);
    
    
    
    
    //ArmMotor
    if(Controller1.ButtonL1.pressing()) { //If button L1 is pressed...
        //...Spin the arm motor forward.
        ArmMotor.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);
    }
    else if(Controller1.ButtonL2.pressing()) { //If the L2 button is pressed...
        //...Spin the arm motor backward.
        ArmMotor.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
    }
    else { //If the the L1 or L2 button is not pressed...
        //...Stop the arm motor.
        ArmMotor.stop(vex::brakeType::brake);
    }
     //LeftIntake Control
    if(Controller1.ButtonR1.pressing()) { //If the R1 button is pressed...
        //...Spin the LeftIntake forward.
        LeftIntake.spin(vex::directionType::fwd, slowClawSpeedPCT, vex::velocityUnits::pct);
    }
    else if(Controller1.ButtonR2.pressing()) { //If the R2 button is pressed...
        //...Spin the LeftIntake backward.
        LeftIntake.spin(vex::directionType::rev, slowClawSpeedPCT, vex::velocityUnits::pct);
    }
    else { //If the R1 or R2 button are not pressed...        
        //...Stop the LeftIntake.
        LeftIntake.stop(vex::brakeType::brake);        
    }
     //Slow RightIntake Control
    if(Controller1.ButtonR1.pressing()) { //If the R1 button is pressed...
        //...Spin the RightIntake forward.
        RightIntake.spin(vex::directionType::fwd, slowClawSpeedPCT, vex::velocityUnits::pct);
    }
    else if(Controller1.ButtonR2.pressing()) { //If the R2 button is pressed...
        //...Spin the RightIntake backward.
        RightIntake.spin(vex::directionType::rev, slowClawSpeedPCT, vex::velocityUnits::pct);
    }
    else { //If the R1 or R2 button are not pressed...        
        //...Stop the RightArmSlurper.
        RightIntake.stop(vex::brakeType::brake);                
    }
    //ChutePush Control
    if(Controller1.ButtonUp.pressing()) { //If the Up button is pressed...
        //...Spin the ChuteMotor forward.
        ChutePush.spin(vex::directionType::fwd, chuteSpeedPCT, vex::velocityUnits::pct);
    }
    else if(Controller1.ButtonDown.pressing()) { //If the Down button is pressed...
        //...Spin the ChuteMotor backward.
        ChutePush.spin(vex::directionType::rev, chuteSpeedPCT, vex::velocityUnits::pct);
    }
    else { //If the Up or Down button are not pressed...        
        //...Stop the ChutePush.
        ChutePush.stop(vex::brakeType::brake);        
    }
    
	vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}

}
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.
// ........................................................................

vex::task::sleep(20); //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(1) {
  vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}    

}

put the motor setup code above the vex::competition

ok

2000000 characters

do you know the problem?

not really since I don’t know where the problem is but that may help

1 Like

oh ok
20 characterss

I’m using a PID loop that worked in RobotC but doesn’t work in Vexcode Text.

float errorL = ((power*12/circ)*360 ) - velocityL;

This is the only line that doesn’t work. It needs a different word for “power” and “velocityL”. I was wondering if anyone knew what words it wants.
Thanks!

I need some help understanding how I can program automatic motions from a keypress on the controller while in drivercontrol mode. The “usercontrol” function/thread reads my drivetrain joystick control code, but sometimes I want to suspend the joystick control and execute an automatic sequence of moves via a keypress. My attempt at this code is here attached. Somehow the "unloadTower " function never seems to execute, and I think it’s because the drivetrain code in the main usercontrol thread is taking over all the time.

Can someone explain how to share motor resources between joystick control and autonomous sequences? For that matter, how it is that the autonomous thread is not superceded by the drivercontrol thread in a real match under the field controller?

(Apologies in advance for the crude code posting. I’m new to this and not sure how to include code in a post.) (fixed by mods)

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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.
  // ..........................................................................
}


void unloadTower(void) {
  //One Button B press executes a series of moves to unload a tower
  
  LeftMotor.spin(reverse,20,pct);
  RightMotor.spin(reverse,20,pct);

  }

/*---------------------------------------------------------------------------*/
/*                                                                           */
/*                              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) {
  // Upon entering user control, define the precise and speed gains for the joysticks

   Controller1.ButtonB.pressed(unloadTower);

  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.
    // ........................................................................

// DRIVETRAIN


// Scale the motor inputs to percent scale
        float leftspin = Controller1.Axis1.position(pct)+Controller1.Axis2.position(pct);
        float rightspin = Controller1.Axis1.position(pct)-Controller1.Axis2.position(pct);

        //Find the largest possible sum of fwdrev and turn joystix
        int max_raw_sum = (int)(abs(Controller1.Axis2.position(pct)) + abs(Controller1.Axis1.position(pct)));
        
        //Find the largest joystick value at this moment
        int max_XYstick_value = (int)(fmax(abs(Controller1.Axis2.position(pct)),abs(Controller1.Axis1.position(pct))));

        //Scale the drive motor inputs to 100 percent scale preserving directionality
        if (max_raw_sum != 0) {
            leftspin  = leftspin / max_raw_sum * max_XYstick_value;
            rightspin   = rightspin / max_raw_sum * max_XYstick_value;
            LeftMotor.spin(fwd,leftspin, velocityUnits::pct);
            RightMotor.spin(fwd,rightspin, velocityUnits::pct); }
             

          else {
            leftspin = 0;
            rightspin = 0;
            LeftMotor.setStopping(brake);
            RightMotor.setStopping(brake);
            LeftMotor.stop();
            RightMotor.stop();}  
             
//END OF DRIVETRAIN

    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);
  }
}

Yes, you are correct that your user control code takes over your macro execution.

You need to give the macro some time to complete. Use this code as a sample for your user control loop:

bool bMacroIsRunning = false;
uint32_t  macroStartTime = 0;
while(1)
{
    int joyVal = Controller1.Axis1.position(pct);
    if( abs(joyVal) > 10 )
    {
        motor1.spin(fwd,joyVal,pct);
        bMacroIsRunning = false; // cancel macro run
    }
    else if( Controller1.ButtonL1.pressing() && bMacroIsRunning==false )
    {  // user pressed L1 to start macro and macro is not running
        macroStartTime = vex::timer::system(); //remember start time
        motor1.spin(reverse,20,pct);
        bMacroIsRunning = true;
    }
    else if( bMacroIsRunning==false ||
              vex::timer::system() > macroStartTime+1000 )
    {  // this gives macro 1 sec to finish
        motor1.stop();
        bMacroIsRunning = false;
    }
    vex::task(sleep(1);
}

When you press the button it will start the macro and remember its start time. Then it will stop the motors only if 1 second will pass since beginning.

User control will only take over if you move joystick while macro is running.

https://api.vexcode.cloud/v5/html/classvex_1_1timer.html