/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// llantas_derechas motor_group 15, 16
// derecha motor 20
// llantas_izquierdas motor_group 12, 13
// izquierda motor 11
// intaker motor 2
// PTO digital_out A
// inercia inertial 6
// catapulta motor 18
// elevacion digital_out B
// EncoderC encoder C, D
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
//
//--------------------------------------------------------ENCODER----------------------------------------------------------
void AVANZA (int distancia) {
// insertamos la posicion, velocidad y direccion que deseamos que tengan los motores.
EncoderC.setPosition (0, degrees);
llantas_derechas.spin (fwd);
derecha.spin (fwd);
llantas_derechas.setVelocity(50,percent);
derecha.setVelocity(50,percent);
llantas_izquierdas.spin (fwd);
izquierda.spin (fwd);
llantas_izquierdas.setVelocity(50,percent);
izquierda.setVelocity(50,percent);
// mientras la posicion del encoder sea mayor a la distancia introducida, los motores iran hacia adelante.
while (! (EncoderC.position (degrees)> distancia)) {
Brain.Screen.print (".% 2f", EncoderC.position (degrees));
Brain.Screen.setCursor (1, 1); // brain screen sirve para imprimir los grados que avanza el enconder, en la pantalla del brain.
wait (100, msec);
Brain.Screen.clearScreen (); // la pantalla se limpia cuando se cumple la condicion.
wait (5,msec);
}
}
//--------------------------------------------- SENSOR INERCIAL--------------------------------------------------------------------------
float objetivo;
float actual=inercia.heading(degrees);
float diferencia=objetivo-actual;
float proporcion=.55; //---se divide 100 entre el valor (x) de grados que se desean para tener la proporcion
float velocidad=proporcion*diferencia;
void giro180(){
while (1==1){
actual=inercia.heading(degrees);
diferencia=objetivo-actual;
velocidad=proporcion*diferencia;
if (velocidad>100){
velocidad=100;
}
if (diferencia>=0){
diferencia=0;
}
llantas_derechas.spin(reverse,velocidad,pct);
derecha.spin(reverse,velocidad,pct);
llantas_izquierdas.spin(forward,velocidad,pct);
izquierda.spin(forward,velocidad,pct);
if (inercia.heading(degrees)>178.850 && inercia.heading(degrees)<180.550){
wait(1.5,msec);
llantas_derechas.stop(hold);
derecha.stop(hold);
llantas_izquierdas.stop(hold);
izquierda.stop(hold);
break;
}
} }
// (2)
float OBJETIVO;
float ACTUAL=inercia.heading(degrees);
float DIFERENCIA=objetivo-actual;
float PROPORCION=1.11; //---se divide 100 entre el valor (x) de grados que se desean para tener la proporcion
float VELOCIDAD=proporcion*diferencia;
void giro90(){
while (1==1){
ACTUAL=inercia.heading(degrees);
DIFERENCIA=objetivo-actual;
VELOCIDAD=proporcion*diferencia;
if (velocidad>100){
velocidad=100;
}
if (diferencia>=0){
diferencia=0;
}
llantas_derechas.spin(reverse,velocidad,pct);
derecha.spin(reverse,velocidad,pct);
llantas_izquierdas.spin(forward,velocidad,pct);
izquierda.spin(forward,velocidad,pct);
if (inercia.heading(degrees)>88.950 && inercia.heading(degrees)<89.99){
wait(1.5,msec);
llantas_derechas.stop(hold);
derecha.stop(hold);
llantas_izquierdas.stop(hold);
izquierda.stop(hold);
break;
}
} }
//---------------------------------------------------------ODOMETRO-----------------------------------------------------
void stop(){
llantas_derechas.stop(hold);
derecha.stop(hold);
llantas_izquierdas.stop(hold);
izquierda.stop(hold);
}
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, ...
}
void autonomous(void) {
inercia.calibrate();
while(inercia.isCalibrating()){
wait(50,msec);
}
llantas_derechas.spin(reverse,velocidad,pct);
derecha.spin(reverse,velocidad,pct);
llantas_izquierdas.spin(forward,velocidad,pct);
izquierda.spin(forward,velocidad,pct);
waitUntil(inercia.rotation(degrees)>=90.0);
if (inercia.heading(degrees)>88.950 && inercia.heading(degrees)<89.99){
llantas_derechas.stop(hold);
derecha.stop(hold);
llantas_izquierdas.stop(hold);
izquierda.stop(hold);
}
}
void usercontrol(void) {
// User control code here, inside the loop
while (1) {
//---------------------------------------- TREN MOTRIZ
//-------------- lado derecho del tren motriz
llantas_derechas.spin(directionType::fwd,Controller1.Axis2.position(percentUnits::pct),velocityUnits::pct);
llantas_derechas.setStopping(coast);
derecha.spin(directionType::fwd,Controller1.Axis2.position(percentUnits::pct),velocityUnits::pct);
derecha.setStopping(coast);
//-------------- lado izqierdo del tren motriz
llantas_izquierdas.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct),velocityUnits::pct);
llantas_izquierdas.setStopping(coast);
izquierda.spin(directionType::fwd,Controller1.Axis3.position(percentUnits::pct),velocityUnits::pct);
izquierda.setStopping(coast);
//--------------------------------------intaker
if (Controller1.ButtonR2.pressing()==1){
intaker.spin(fwd,600,rpm);
}
else if(Controller1.ButtonR1.pressing()==1){
intaker.spin(reverse,600,rpm);
}
else{
intaker.stop(hold);
}
//------------------------------------piston del PTO
if (Controller1.ButtonL1.pressing()==1){
PTO.set(true);
}
else if(Controller1.ButtonL2.pressing()==1){
PTO.set(false);
}
//----------------------------piston de la elevacion
if (Controller1.ButtonR1.pressing()==1){
elevacion.set(true);
}
else if(Controller1.ButtonR2.pressing()==1){
elevacion.set(false);
}
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);
}
}
In order to help you fix the issue, what is wrong with your gyro? What about it is not working?
We are in the same boat, I’m trying to get my stuff working before worlds and I have no idea what to do.