#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include "vex.h"
using namespace vex;
// Brain should be defined by default
brain Brain;
// START IQ MACROS
#define waitUntil(condition) \
do { \
wait(5, msec); \
} while (!(condition))
#define repeat(iterations) \
for (int iterator = 0; iterator < iterations; iterator++)
// END IQ MACROS
// Robot configuration code.
controller Controller = controller();
motor LeftDriveSmart = motor(PORT1, 0.5, false);
motor RightDriveSmart = motor(PORT6, 0.5, true);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 200, 173, 76, mm, 1);
motor Azul = motor(PORT5, false);
motor Canasta = motor(PORT11, true);
motor ShooterMotorA = motor(PORT4, false);
motor ShooterMotorB = motor(PORT10, false);
motor_group Shooter = motor_group(ShooterMotorA, ShooterMotorB);
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool DrivetrainLNeedsToBeStopped_Controller = true;
bool DrivetrainRNeedsToBeStopped_Controller = true;
// define a task that will handle monitoring inputs from Controller
int rc_auto_loop_function_Controller() {
// process the controller input every 20 milliseconds
// update the motors based on the input values
while(true) {
if(RemoteControlCodeEnabled) {
// calculate the drivetrain motor velocities from the controller joystick axies
// left = AxisA
// right = AxisD
int drivetrainLeftSideSpeed = Controller.AxisA.position();
int drivetrainRightSideSpeed = Controller.AxisD.position();
// check if the value is inside of the deadband range
if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
// check if the left motor has already been stopped
if (DrivetrainLNeedsToBeStopped_Controller) {
// stop the left drive motor
LeftDriveSmart.stop();
// tell the code that the left motor has been stopped
DrivetrainLNeedsToBeStopped_Controller = false;
}
} else {
// reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
DrivetrainLNeedsToBeStopped_Controller = true;
}
// check if the value is inside of the deadband range
if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
// check if the right motor has already been stopped
if (DrivetrainRNeedsToBeStopped_Controller) {
// stop the right drive motor
RightDriveSmart.stop();
// tell the code that the right motor has been stopped
DrivetrainRNeedsToBeStopped_Controller = false;
}
} else {
// reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
DrivetrainRNeedsToBeStopped_Controller = true;
}
// only tell the left drive motor to spin if the values are not in the deadband range
if (DrivetrainLNeedsToBeStopped_Controller) {
LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
LeftDriveSmart.spin(forward);
}
// only tell the right drive motor to spin if the values are not in the deadband range
if (DrivetrainRNeedsToBeStopped_Controller) {
RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
RightDriveSmart.spin(forward);
}
}
// wait before repeating the process
wait(20, msec);
}
return 0;
}
task rc_auto_loop_task_Controller(rc_auto_loop_function_Controller);
#pragma endregion VEXcode Generated Robot Configuration
#include "vex.h"
#include "iq_cpp.h"
using namespace vex;
//
//----------------------------------------------------------------------------
// Modulo: Cocodrile tabasco 2
// Ver: "2.7"
// Autor: Daniel de "programming team"
// Fecha dev: 1/11/2022-12/12/2022
// Descripcion: Programacion del reto 2022-2023 VEX IQ Slapshot
//
//----------------------------------------------------------------------------
//ChangeLog ( c++ ver)
//----------------------------------------------------------------------------
//2.2 se remasterizo desde cero la programacion en c++
//2.3 Se removieron los comentarios por defecto y se agregaron unos mas acertados
//2.4: Se agrego soporte para Autonumus skills
//2.5: Se agrego soporte para la nueva version del robot
//2.5.1: Se corrigieron los errores del motor del dispensador azul
//2.6 Se agregaron MAS comentarios y se removieron los touch leds
//2.6.1 Se acomodo algo mas la programacion y se corrigieron algunos bucles
//!! 2.6.2-3 no se registraron debido a algunos errores
//2.6.4 Se agrego un temporizador y un modo pinch (Un endGame)
//2.6.5 Removidas varias lineas innecesarias
//2.7.0 Se agrego compatibilidad con el nuevo robot
//
//----------------------------------------------------------------------------
//----- C O D I G O D E L P R O Y E C T O -----//
//Se definen algunas variables, bloques y funciones
void myblockfunction_slot_nombre_en_row_column(double myblockfunction_slot_nombre_en_row_column__row, double myblockfunction_slot_nombre_en_row_column__column);
void myblockfunction_Slot_vacio();
void myblockfunction_sonido();
//Todo lo anteior son "defines" para funciones
int Brain_precision = 0;//Calidad del brain
float contador, selector, On_, Off_, Control_, MenuEnd, Tiempo_, DPS_; //Variables
event mensaje1 = event();
event Menu = event();
event Driver = event();
event Autonumus = event();
event Slot3 = event();
event Slot4 = event();
event Slot5 = event();
event RGB1 = event();
event RGB2 = event();
event JB = event();
event Tiempo = event();
event pinch = event();
//Partes de las funciones
//Este bloque le da un funcionamiento a los slots llenos
void myblockfunction_slot_nombre_en_row_column(double myblockfunction_slot_nombre_en_row_column__row, double myblockfunction_slot_nombre_en_row_column__column) {
MenuEnd = On_;
RGB1.broadcast();
Brain.Screen.clearScreen();
Brain.Screen.setCursor(myblockfunction_slot_nombre_en_row_column__row, myblockfunction_slot_nombre_en_row_column__column);
}
// Este bloque sirve para darle un funcionamiento a los slots vacios
void myblockfunction_Slot_vacio() {
MenuEnd = On_;
Brain.Screen.clearScreen();
Brain.Screen.setCursor(3, 9);
Brain.playSound(doorClose);
Brain.Screen.print(". ");
wait(0.3, seconds);
Brain.playSound(doorClose);
Brain.Screen.print(". ");
wait(0.3, seconds);
Brain.playSound(doorClose);
Brain.Screen.print(".");
wait(0.3, seconds);
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
MenuEnd = Off_;
Menu.broadcast();
}
//Este es solamente estetico
void myblockfunction_sonido() {
Brain.playSound(doorClose);
wait(0.3, seconds);
}
//Bloque inicial, se definen las velocidades, valores, etc
int whenStarted1() {
RemoteControlCodeEnabled = false;
Canasta.setMaxTorque(100.0, percent);
Canasta.setVelocity(100.0, percent);
Shooter.setMaxTorque(100.0, percent);
Shooter.setVelocity(100.0, percent);
Azul.setMaxTorque(100.0, percent);
Azul.setVelocity(100.0, percent); //todas las velocidaded y torques son igual a 100
Drivetrain.setDriveVelocity(100,percent);
Azul.setStopping(hold);
Canasta.setStopping(hold);
Shooter.setStopping(hold); //Los motores se quedan manteniendo fuerza al detenerse
Azul.stop();
Shooter.stop();
Canasta.stop() ;
Drivetrain.stop(); //Se corrige un error en el cual el robot comienza a moverse solo
selector = 1.0;
contador = 1.0;//bases para el menu
Off_ = 5.0;
On_ = 10.0; //on y off, para activar/desactivar slots y el menu
Tiempo_ = 60; //Contador para el cerebro
Control_ = Off_; //para un refuerzo al drive block
MenuEnd = Off_; //El menu NO ha terminado
DPS_ = 0.7; //Delay entre cambio de leds
Menu.broadcast(); //Iniciar el menu
return 0;
}
//Bloques led
void onevent_RGB1_0() {
RGB2.broadcast();
/*
TouchLED9.setFade(slow);
TouchLED9.setBrightness(100);
while (true) {
wait(DPS_, seconds);
TouchLED9.setColor(red);
wait(DPS_, seconds);
TouchLED9.setColor(red_orange);
wait(DPS_, seconds);
TouchLED9.setColor(orange);
wait(DPS_, seconds);
TouchLED9.setColor(yellow);
wait(DPS_, seconds);
TouchLED9.setColor(yellow_green);
wait(DPS_, seconds);
TouchLED9.setColor(green);
wait(DPS_, seconds);
TouchLED9.setColor(blue_green);
wait(DPS_, seconds);
TouchLED9.setColor(blue);
wait(DPS_, seconds);
TouchLED9.setColor(blue_violet);
wait(DPS_, seconds);
TouchLED9.setColor(purple);
wait(DPS_, seconds);
TouchLED9.setColor(violet);
wait(DPS_, seconds);
TouchLED9.setColor(red_violet);
wait(20, msec);
*/
}
//}
//Lo mismo que en la parte de arriba, pero con el segundo led
void onevent_RGB2_0() {
/*
TouchLED10.setFade(slow);
TouchLED10.setBrightness(100);
while (true) {
wait(DPS_, seconds);
TouchLED10.setColor(red);
wait(DPS_, seconds);
TouchLED10.setColor(red_orange);
wait(DPS_, seconds);
TouchLED10.setColor(orange);
wait(DPS_, seconds);
TouchLED10.setColor(yellow);
wait(DPS_, seconds);
TouchLED10.setColor(yellow_green);
wait(DPS_, seconds);
TouchLED10.setColor(green);
wait(DPS_, seconds);
TouchLED10.setColor(blue_green);
wait(DPS_, seconds);
TouchLED10.setColor(blue);
wait(DPS_, seconds);
TouchLED10.setColor(blue_violet);
wait(DPS_, seconds);
TouchLED10.setColor(purple);
wait(DPS_, seconds);
TouchLED10.setColor(violet);
wait(DPS_, seconds);
TouchLED10.setColor(red_violet);
wait(20, msec);
*/
//inutilizado por ahora
}
void onevent_Tiempo_0(){ //Reloj
Brain.Screen.newLine();
for (int i = 0; i <= 45; i++) {
Brain.Screen.setCursor(Brain.Screen.row(),1);
Brain.Screen.print(" ");
Brain.Screen.print("Tiempo_");
wait(1,seconds);
Tiempo_ = Tiempo_ - 1;
Brain.Screen.clearLine(Brain.Screen.row());
if (Tiempo_ == 15){
pinch.broadcastAndWait();
}
}
}
void onevent_pinch_0(){
Brain.playSound(alarm);
for (int i = 0; i <= 15; i++) {
Brain.playSound(doorClose);
wait(1,seconds);
}
Brain.playSound(powerDown);
}
void onevent_JB_0(){
Brain.playNote(3, 2, 250);
Brain.playNote(3, 2, 250);
Brain.playNote(3, 2, 500);
Brain.playNote(3, 2, 250);
Brain.playNote(3, 2, 250);
Brain.playNote(3, 2, 500);
Brain.playNote(3, 2, 250);
Brain.playNote(3, 4, 250);
Brain.playNote(3, 0, 250);
Brain.playNote(3, 1, 250);
Brain.playNote(3, 2, 1000);
}
//----- C O N T R O L E S -----
//Iniciar temporizador
void onevent_ControllerButtonLDown_pressed_0(){
if (Control_ == On_){
while (!(!Controller.ButtonLDown.pressing())){
Tiempo.broadcast();
}
}
}
//Moverse para acomodar los discos
void onevent_ControllerButtonLUp_pressed_0(){
if (Control_ == On_){
while (!(!Controller.ButtonLUp.pressing())){
Drivetrain.driveFor(reverse,15,mm);
Drivetrain.driveFor(forward,15,mm);
}
}
}
//Canasta, recibir
void onevent_ControllerButtonRUp_pressed_0() {
if (Control_ == On_) {
while (!(!Controller.ButtonRUp.pressing())) {
Canasta.spin(forward);
wait(20, msec);
}
Canasta.stop();
}
}
// Gancho, alzar
void onevent_ControllerButtonEUp_pressed_0() {
if (Control_ == On_) {
while (!(!Controller.ButtonEUp.pressing())) {
Azul.spin(forward);
wait(20, msec);
}
Azul.stop();
}
}
// Shooter, lanzar
void onevent_ControllerButtonFUp_pressed_0() {
if (Control_ == On_) {
while (!(!Controller.ButtonFUp.pressing())) {
Shooter.spin(forward);
wait(20, msec);
}
Shooter.stop();
}
}
//Canasta, enviar
void onevent_ControllerButtonRDown_pressed_0() {
if (Control_ == On_) {
while (!(!Controller.ButtonRDown.pressing())) {
Canasta.spin(reverse);
wait(20, msec);
}
Canasta.stop();
}
}
//Solo para no tener ningun inconveniente al conducir:
// Shooter, x
void onevent_ControllerButtonFDown_pressed_0() {
if (Control_ == On_) {
while (!(!Controller.ButtonFDown.pressing())) {
Shooter.spin(reverse);
wait(20, msec);
}
Shooter.stop();
}
}
// Gancho, bajar
void onevent_ControllerButtonEDown_pressed_0() {
if (Control_ == On_) {
while (!(!Controller.ButtonEDown.pressing())) {
Azul.spin(reverse);
wait(20, msec);
}
Azul.stop();
//Controles listos
}
}
// Esta parte es la mas importante
//----- M E N U -----//
void onevent_buttonCheck_pressed_0() {
while (true){
if (MenuEnd == Off_) {
if (selector == 1.0) {
Driver.broadcastAndWait();
}
if (selector == 2.0) {
Autonumus.broadcast();
}
if (selector == 3.0) {
Slot3.broadcast();
}
if (selector == 4.0) {
Slot4.broadcast();
}
if (selector == 5.0) {
Slot5.broadcast();
}
}
}
}
//
//Calidad al hacer print el el brain
const char* printToBrain_numberFormat() {
switch(Brain_precision){
case 0: return "%.0f"; // 0 decimal places (1)
case 1: return "%.1f"; // 1 decimal place (0.1)
case 2: return "%.2f"; // 2 decimal places (0.01)
case 3: return "%.3f"; // 3 decimal places (0.001)
default: return "%f"; // use the print system default for everthing else
}
}
//Esta seccion se encarga de print-ear el menu (texto)
void onevent_Menu_0() {
if (MenuEnd == Off_) {
while (!(MenuEnd == On_)) {
Brain.Screen.clearLine(contador);
if (selector == contador) {
Brain.Screen.print(">");
}
Brain.Screen.print("Slot: ");
Brain.Screen.print(printToBrain_numberFormat(), static_cast<float>(contador));
contador = contador + 1.0;
if (contador > 5.0) {
contador = 1.0;
}
Brain.Screen.setCursor(contador, 1);
wait(20, msec);
}
}
}
void onevent_buttonUp_pressed_0() {
if (MenuEnd == Off_) {
Brain.playSound(doorClose);
if (selector > 1.0) {
selector = selector + -1.0;
}
}
}
void onevent_buttonDown_pressed_0() {
if (MenuEnd == Off_) {
Brain.playSound(doorClose);
if (5.0 > selector) {
selector = selector + 1.0;
}
}
}
//A partir de aqui se configuran las acciones de los slots
// Driver
void onevent_Driver_0() {
myblockfunction_slot_nombre_en_row_column(3.0, 7.0);
RemoteControlCodeEnabled = true;
Control_ = On_;
wait(0.3, seconds);
Tiempo.broadcast();
Brain.Screen.print("D");
myblockfunction_sonido();
Brain.Screen.print("r");
myblockfunction_sonido();
Brain.Screen.print("i");
myblockfunction_sonido();
Brain.Screen.print("v");
myblockfunction_sonido();
Brain.Screen.print("e");
myblockfunction_sonido();
Brain.Screen.print("r");
myblockfunction_sonido();
//Este efecto se repite con los diferentes slots
}
// Autonumus
void onevent_Autonumus_0() {
myblockfunction_slot_nombre_en_row_column(3.0, 6.0);
Brain.Screen.print("V");
myblockfunction_sonido();
Brain.Screen.print("i");
myblockfunction_sonido();
Brain.Screen.print("r");
myblockfunction_sonido();
Brain.Screen.print("t");
myblockfunction_sonido();
Brain.Screen.print("u");
myblockfunction_sonido();
Brain.Screen.print("a");
myblockfunction_sonido();
Brain.Screen.print("l");
myblockfunction_sonido();
// !!
//waitUntil((TouchLED9.pressing() || TouchLED10.pressing()));
waitUntil (Brain.buttonCheck.pressing());
Drivetrain.driveFor(forward,100,mm);
Drivetrain.turnFor(left,90,degrees);
}
void onevent_Slot3_0() {
myblockfunction_Slot_vacio();
myblockfunction_slot_nombre_en_row_column(3.0,1.0);
Brain.Screen.print("J");
myblockfunction_sonido();
Brain.Screen.print("i");
myblockfunction_sonido();
Brain.Screen.print("n");
myblockfunction_sonido();
Brain.Screen.print("g");
myblockfunction_sonido();
Brain.Screen.print("l");
myblockfunction_sonido();
Brain.Screen.print("e");
myblockfunction_sonido();
Brain.Screen.print(" ");
myblockfunction_sonido();
Brain.Screen.print("b");
myblockfunction_sonido();
Brain.Screen.print("e");
myblockfunction_sonido();
Brain.Screen.print("l");
myblockfunction_sonido();
Brain.Screen.print("l");
myblockfunction_sonido();
Brain.Screen.print("s");
myblockfunction_sonido();
wait(1,seconds);
JB.broadcastAndWait();
}
// Sin usar por el momento
void onevent_Slot4_0() {
myblockfunction_Slot_vacio();
}
// Sin usar por el momento
void onevent_Slot5_0() {
myblockfunction_Slot_vacio();
}
//Main, este define aun mas cosas para el correcto funcionamiento de la programacion
int main() {
RGB1(onevent_RGB1_0);
RGB2(onevent_RGB2_0);
Controller.ButtonRUp.pressed(onevent_ControllerButtonRUp_pressed_0);
Controller.ButtonEUp.pressed(onevent_ControllerButtonRUp_pressed_0);
Controller.ButtonLUp.pressed(onevent_ControllerButtonEUp_pressed_0);
Controller.ButtonFUp.pressed(onevent_ControllerButtonFUp_pressed_0);
Controller.ButtonRDown.pressed(onevent_ControllerButtonRDown_pressed_0);
Controller.ButtonFDown.pressed(onevent_ControllerButtonFDown_pressed_0);
Controller.ButtonLDown.pressed(onevent_ControllerButtonEDown_pressed_0);
Controller.ButtonEDown.pressed(onevent_ControllerButtonEDown_pressed_0);
Brain.buttonCheck.pressed(onevent_buttonCheck_pressed_0);
Menu(onevent_Menu_0);
Brain.buttonUp.pressed(onevent_buttonUp_pressed_0);
Brain.buttonDown.pressed(onevent_buttonDown_pressed_0);
Driver(onevent_Driver_0);
Autonumus(onevent_Autonumus_0);
Slot3(onevent_Slot3_0);
Slot4(onevent_Slot4_0);
Slot5(onevent_Slot5_0);
wait(15, msec);
whenStarted1();
}