How do you make an LCD autonomous selection with PROS?

  1. 6 months ago

    InValidFire

    7 Dec 2017 Dunwoody, GA 1264B

    Hiya, recently been trying to learn how to use PROS and would like to set up a way to select which autonomous we run before each game. I've no idea where to even start... Could anyone point me in the right direction?

    The variable we're using for our autonomous selection is 'autover', I would like the screen to change the value (thus changing loaded autonomous code) with a button press, and display the name of the loaded autonomous.

    Where would I write this code so it doesn't interfere with anything, but also runs before the autonomous period? And maybe an example of how it'd be done would be nice, there's a lot of lcd functions... bit confusing.

    Thanks!

  2. InValidFire

    7 Dec 2017 Dunwoody, GA 1264B
    Edited 6 months ago by InValidFire

    Think posting my autonomous script may be handy...

    /** @file auto.c
     * @brief File for autonomous code
     *
     * This file should contain the user autonomous() function and any functions related to it.
     *
     * Any copyright is dedicated to the Public Domain.
     * http://creativecommons.org/publicdomain/zero/1.0/
     *
     * PROS contains FreeRTOS (http://www.freertos.org) whose source code may be
     * obtained from http://sourceforge.net/projects/freertos/files/ or on request.
     */
    
    #include "main.h"
    
    /*
     * Runs the user autonomous code. This function will be started in its own task with the default
     * priority and stack size whenever the robot is enabled via the Field Management System or the
     * VEX Competition Switch in the autonomous mode. If the robot is disabled or communications is
     * lost, the autonomous task will be stopped by the kernel. Re-enabling the robot will restart
     * the task, not re-start it from where it left off.
     *
     * Code running in the autonomous task cannot access information from the VEX Joystick. However,
     * the autonomous function can be invoked from another task if a VEX Competition Switch is not
     * available, and it can access joystick information if called in this way.
     *
     * The autonomous task may exit, unlike operatorControl() which should never exit. If it does
     * so, the robot will await a switch to another mode or disable/enable cycle.
     */
    void autonomous() {
      int autover; //Sets variable for autonomous version.
      autover = 0; //Sets autover to 0. Change this to change loaded autonomous operation.
      /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
       *  [+]COMPETITION OPS:  [-]SKILLS OPS:                    *
       *  DROP-OFF = 0         SKILLFUL = -1                     *
       *                                                         *
       *                                                         *
       *                                                         *
       *                                                         *
       * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
      //////////////////////////////// AUTONOMOUS OPERATIONS ////////////////////////////////
    
      if(autover == 0) {
        /* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         *  OPERATION: DROP-OFF.                                 *
         *  This autonomous plans to grab the mobile goal in the *
         *  parking space, bring it back, and drop it in the     *
         *  10-point zone behind the starting bar.               *
         * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
        setManipulatorTimed(-127, 500); //Lowers manipulator.
        motorStopAll(); //Stops all motors.
        setDriveTimed(127, 127, 1350); //Moves forward to the mobile goal on parking location.
        motorStopAll(); //Stops all motors.
        setManipulatorTimed(127, 1500); //Raises manipulator, hopefully lifting mobile goal.
        motorStopAll(); //Stops all motors.
        pivotLeftTimed(127, 500); //Turns around facing starting bar.
        motorStopAll(); //Stops all motors.
        setDriveTimed(127, 127, 1300); //Moves foward to the starting bar.
        motorStopAll(); //Stops all motors.
        setManipulatorTimed(-127, 500); //Lowers manipulator, getting ready to drop mobile goal in 10-point zone.
        motorStopAll(); //Stops all motors.
        setDriveTimed(-127, -127, 500); //Backs up, dropping mobile goal behind 10-point zone.
        motorStopAll();
      }
      if(autover == -1); {
        /* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         *  OPERATION: DIVIDE&CONQUER                            *
         *  This autonomous plans to last a minute long,         *
         *  grabbing all mobile goals on the field, and dropping *
         *  them in the scoring zones.                           *
         * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
        setManipulatorTimed(-127, 500); //Lowers manipulator.
        motorStopAll(); //Stops all motors.
    
      }
    }

    Plan on having at least 3 Autonomous codesets developed eventually. Just need a system to easily switch them out.

  3. callen

    7 Dec 2017 Braintree, MA, USA

    Put the code in init.c so it runs in the initialization instead of the autonomous or operator control parts. If that's the only thing you want to get back, you could return an appropriate value. Otherwise you might choose between things like returning a struct, using global variables, or passing pointers. I consider passing pointers to be the ideal approach. But using global variables can be easier to pick up. I'm not a fan of the struct approach to returning multiple types of values.

    Inside init.c you can build the code like many posted on the forums. Mostly it's looking for button presses and then waiting for button releases in a while loop. You can use certain buttons at certain times to exit the while loop, while other buttons do whatever selection and similar you want.

    More ideally, you won't put that all in init.c anyway, but make a separate file for it. Then call that from within init.c. That way you might have a few different initialization files running different things while keeping it all clean. You could also run tasks so you could, for example, start up a gyro and have the LCD do some stuff while the gyro is given time to fully initialize.

  4. InValidFire

    7 Dec 2017 Dunwoody, GA 1264B
    Edited 6 months ago by InValidFire

    Okay, I think I've found something I can base mine off of, didn't realize so many people asked this before. (NOTE: Use Google to search this site, not forum search)

    One question though, could you explain what numbers go with what buttons? Like how would I tell it to do something when the left button is pressed? Literally my first time messing with LCD's (But gotta learn some time).

    Checked the 'api.h' for a bit of an explanation, didn't help my confusion much though.

    /**
     * Reads the user button status from the LCD display.
     *
     * For example, if the left and right buttons are pushed, (1 | 4) = 5 will be returned. 0 is
     * returned if no buttons are pushed.
     *
     * @param lcdPort the LCD to poll, either uart1 or uart2
     * @return the buttons pressed as a bit mask
     */
    unsigned int lcdReadButtons(PROS_FILE *lcdPort);

    EDIT: After doing some research, I've found it out. Thanks!

  5. When I try to use init.c, I can't get it to work. And if you look in at the comments for init.c in main.h, it says the user would need to set up their own pre auton task (like the one in robotC). Meaning any code won't work. This is my problem with my auton selector. Does anybody know how to set up a pre auton? Would be really helpful, thank you.

 

or Sign Up to reply!