PROSe Sample Code: Specifics this time

So my team is experiment with PROSe and its capabilities. We are getting a VEX speaker and want to play sounds. We also have an LCD screen and want it to display the battery level of the main battery. It also has to function (drive, etc.). Can someone give me some basic sample code that accomplishes these things (just two motor drive for functionality, one if you want, it’s just an example.) I don’t know a great deal about programming and hopefully my partner will have an account soon (he is the programmer in the group) and can contribute to the thread.

We are working on our example code, particularly for less often used aspects like the speaker. I took this example from the automated test bench for the VEX speaker which plays a short melody in autonomous mode if placed in auto.c:


void autonomous() {
    speakerInit();
    speakerPlayRtttl("Test:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p");
}

Note that speakerPlayRtttl waits for the song to finish before continuing. If the song is to be played during driver control or autonomous while also performing other operations, start a new task and play the song inside it. PROS also can play multiple tracks to include harmony with a song; for details, see speakerPlayArray.

Taken from init.c in some old robot code of ours:


void initialize() {
    unsigned int voltage;
    // Change "uart1" to "uart2" if LCD is plugged into port marked "UART 2"
    lcdInit(uart1);
    lcdSetText(uart1, 1, "Purdue SIGBOTS");
    // Displays battery level properly as a psuedo-decimal
    voltage = powerLevelMain();
    lcdPrint(uart1, 2, "Batt: %d.%03d V", voltage / 1000, voltage % 1000);
}

Since powerLevelMain returns the voltage as millivolts (voltage * 1000), a reading of 7.2 V will return 7200. The division and modulus operators properly reformat the reading back into volts.

A basic example for tank drive is available in the PROS online documentation which takes the two vertical joystick axes and sends them directly to motor ports 2 and 9. The function belongs in opcontrol.c and is reproduced here:


void operatorControl() {
    while (1) {
        // Read joystick values
        int joystick1 = joystickGetAnalog(1, 3);
        int joystick2 = joystickGetAnalog(1, 4);
        // Optionally process joystick values
        // Send joystick outputs to motors
        motorSet(2, joystick1);
        motorSet(9, joystick2);
        // Joystick and motor values refreshed every 20 ms
        delay(20);
    }
}

Awesome!!! Thanks so much!!!

How might you put a song on the cortex to play?

@Jabibi @frydaddy07

What exactly are you asking for? I’m not sure I follow. MP3 and audio files aren’t supported by the PROS kernel since it’s somewhat beyond the scope of what a typical team needs. It might be possible to port an audio decoder to the Cortex. However, I’m somewhat hesitant that the program might be too large to fit on the Cortex, esp. combined with the actual audio file.

@edjubuh I know a lot more about this and rtttl format and stuff now. Thanks!

My apologies, I had forgotten that PROS documentation has been updated (we made the update, and it only recently went live due to winter break) with the old tutorial covering the VEX Speaker: http://pros.cs.purdue.edu/tutorials/speaker

Hey, how to upload firmware to the microcontroller?

Tony, how do you have the Cortex connected to your computer? You may be able to find drivers for macOS that support USB A-A operation. Only the Programming Hardware Kit works out of the box.