New to Coding

I am new to vexcode text and need just some general help, tips, anything!
All help is greatly accepted!

P.S. I just need mostly autonomous help.

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

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// FLMotor motor 1
// FRMotor motor 10
// RLMotor motor 11
// RRMotor motor 20
// Tray motor 5
// ClawUpDown motor 6
// Claw motor 7
// Controller1 controller
// ---- 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
//Use these variables to set the speed of the arm and claw.
int armSpeedPCT = 100;
int slowClawSpeedPCT = 100;
int chuteSpeedPCT = 70;
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
Brain.Screen.newLine();
Brain.Screen.print(“SUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCCSUCC”);
//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.

    FRMotor.spin(vex::directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);
    FLMotor.spin(vex::directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct);
    RRMotor.spin(vex::directionType::fwd, (Controller1.Axis2.value()), vex::velocityUnits::pct);
    RLMotor.spin(vex::directionType::fwd, (Controller1.Axis3.value()), vex::velocityUnits::pct); 

//ArmMotor
if(Controller1.ButtonL1.pressing()) { //If button L1 is pressed...
    //...Spin the arm motor forward.
    Tray.spin(vex::directionType::fwd, armSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonL2.pressing()) { //If the L2 button is pressed...
    //...Spin the arm motor backward.
    Tray.spin(vex::directionType::rev, armSpeedPCT, vex::velocityUnits::pct);
}
else { //If the the L1 or L2 button is not pressed...
    //...Stop the arm motor.
    Tray.stop(vex::brakeType::brake);
}
 //LeftIntake Control
if(Controller1.ButtonR1.pressing()) { //If the R1 button is pressed...
    //...Spin the LeftIntake forward.
    Claw.spin(vex::directionType::fwd, slowClawSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonR2.pressing()) { //If the R2 button is pressed...
    //...Spin the LeftIntake backward.
    Claw.spin(vex::directionType::rev, slowClawSpeedPCT, vex::velocityUnits::pct);
}
else { //If the R1 or R2 button are not pressed...        
    //...Stop the LeftIntake.
    Claw.stop(vex::brakeType::brake);        
}
//ChutePush Control
if(Controller1.ButtonUp.pressing()) { //If the Up button is pressed...
    //...Spin the ChuteMotor forward.
    ClawUpDown.spin(vex::directionType::fwd, chuteSpeedPCT, vex::velocityUnits::pct);
}
else if(Controller1.ButtonDown.pressing()) { //If the Down button is pressed...
    //...Spin the ChuteMotor backward.
    ClawUpDown.spin(vex::directionType::rev, chuteSpeedPCT, vex::velocityUnits::pct);
}
else { //If the Up or Down button are not pressed...        
    //...Stop the ChutePush.
    ClawUpDown.stop(vex::brakeType::brake);        
}

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 (true) {
wait(100, msec);
}
}

1 Like

Get Vex’s template for driver control and for autonomous. Also, welcome to vexforum!

1 Like

Thanks!
I already wrote the driver control. Just need help on mostly autonomous. If it’s helpful I used to do RobotC. Also if it’s helpful, I have the comp template.

1 Like

Uh, im not great at programming, and im sure @holbrook or @John_TYler could help you if you have issues.

1 Like

Welcome to the VEX Forum @BoredFish!

Personally, I would start with the tutorials under the file menu. There are helpful videos embedded directly into VEXcode. Once you get the overview of VEXcode, there are examples for most common actions or tasks to open and look at. You can use the sample programs to get an idea of motor commands and sensor use in VEXcode text.

There is also an awesome help menu right in VEXcode Text near the top right for any specific questions at that point. Hope this helps!

3 Likes

Yes! That helps a lot. I will use those most definitely. But most of those tutorials only use two drive motors and I use 4 drive motors. But I will look into the help section! It wasn’t there when I was first trying vexcode.

1 Like

Welcome @BoredFish!

The code you posted built fine - if you have any specific problems with future code, feel free to post it (remember to wrap it in [code]…[/code] tags for formatting!) along with an adequate description of the problem and someone will be happy to take a look at it for you.

If you’re new to programming in general, or want a VEXcode specific refresher, you may also be interested in the STEM labs.

3 Likes

if it is helpful here is some pictures of my robot:
IMG_0037 IMG_0038 IMG_0039 IMG_0040 IMG_0041 IMG_0043 IMG_0044

1 Like

What does armSpeedPCT do, I’m new to this VEXcode V5 Text stuff too

1 Like

It’s just setting a specific speed so that when they tell motor two, for example, to move they would just put armspeedPCT instead of 50. This makes it easier to change a motors speed.

This is correct and it is a good practice in general to do this.

However I would add that it’s better to use the #define preprocessor directive rather than initializing a bunch of variables whose values never change while the program runs.

The syntax for the #define directive is as follows. Traditionally, such directives are placed at or near the top of the file:

#define MOTOR_SPEED_PCT 50

Then, later in the program, you can use MOTOR_SPEED_PCT in the same way you would use a variable. By convention, constants established with #define have names in all caps, though this is not mandatory.

The disadvantage of using a variable for this sort of thing is that every time you reference it, the value of the variable has to be retrieved from memory, which takes some time. If you instead use #define, the constant you define is swapped out for its value by the pre-processor before the code is compiled, so you essentially have a hard-coded value that can be easily modified by changing only one line.

7 Likes

I have a question. I made my drivetrain not through the config but manually. I want to make a variable so they can spin all at the same time but, I don’t know how to. Any help?

motor_group is probably what you are looking for.
Or you can just make a function with statements for all of the motors and just call that

Could you possibly show an example? (Help is giving nothing)

Here’s an example of a motor group. Once it is declared the group is coded pretty much the same way as a motor.

motor_group leftDrive(leftFront,leftBack);
leftDrive.spin(forward,100,pct);
1 Like

Thank you so much. That was super helpful