This commit is contained in:
InventorXtreme 2024-02-24 12:00:25 -05:00
parent a7404de94c
commit 5f8419afad
2 changed files with 270 additions and 73 deletions

View file

@ -36,7 +36,21 @@
+ Opposing side
+ Scores 9 points
+ Can counter other teams
+ Currently a legacy auton
6. AUTON 6
Push auton. Moves 2ft backward then 0.5ft forward.
Push auton. Moves the same amount as auton 0 forward, then reverses.
+ Utility auton
7. AUTON 7
Allows us to bowl triballs off the top of the robot, then drives forward to push them into goal.
+ Skills auton
8. AUTON 8
Drives forward, grabs triball, then turns around and pushes two field triballs to other side.
+ Opposing Side
+ Elim auton
+ Refined version of AUTON 5
+ Can counter other teams
9. AUTON 9
Drives forward and pushes three triballs into the goal. Also attempts to score our match load.
+ Our side
+ Can counter other teams
+ Elim auton

View file

@ -9,7 +9,9 @@
/**
* You should add more #includes here
*/
#include "display/lv_core/lv_obj.h"
#include "display/lv_misc/lv_task.h"
#include "display/lv_objx/lv_img.h"
#include "okapi/api.hpp"
#include "okapi/api/device/motor/abstractMotor.hpp"
#include "okapi/api/units/QLength.hpp"
@ -27,6 +29,62 @@
// 1 2 3 5 //left
// 7 8 9 10 //right
// FILE HANDLE CODE:
typedef FILE *pc_file_t;
static lv_fs_res_t pcfs_open(void *file_p, const char *fn, lv_fs_mode_t mode) {
errno = 0;
const char *flags = "";
if (mode == LV_FS_MODE_WR)
flags = "wb";
else if (mode == LV_FS_MODE_RD)
flags = "rb";
else if (mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
flags = "a+";
char buf[256];
sprintf(buf, "/%s", fn);
pc_file_t f = fopen(buf, flags);
if (f == NULL)
return LV_FS_RES_UNKNOWN;
else {
fseek(f, 0, SEEK_SET);
pc_file_t *fp = (pc_file_t *)file_p;
*fp = f;
}
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_close(void *file_p) {
pc_file_t *fp = (pc_file_t *)file_p;
fclose(*fp);
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_read(void *file_p, void *buf, uint32_t btr,
uint32_t *br) {
pc_file_t *fp = (pc_file_t *)file_p;
*br = fread(buf, 1, btr, *fp);
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_seek(void *file_p, uint32_t pos) {
pc_file_t *fp = (pc_file_t *)file_p;
fseek(*fp, pos, SEEK_SET);
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_tell(void *file_p, uint32_t *pos_p) {
pc_file_t *fp = (pc_file_t *)file_p;
*pos_p = ftell(*fp);
return LV_FS_RES_OK;
}
// end file drivers
int autonpick = 0;
int automod = 0;
lv_res_t sa0(lv_obj_t *btn) {
@ -125,7 +183,8 @@ bool is_held(bool *log, bool ap) {
* to keep execution time for this mode under a few seconds.
*/
void initialize() {
pros::lcd::initialize();
// pros::lcd::initialize();
// pros::lcd::set_text(1, "Hello PROS User!");
pros::lcd::register_btn1_cb(on_center_button);
@ -148,7 +207,7 @@ void disabled() {}
* starts.
*/
void competition_initialize() {
pros::Imu IMU(19);
pros::Imu IMU(19);
IMU.reset(true);
IMU.tare();
pros::delay(200);
@ -226,7 +285,7 @@ void autonomous() {
upflap.set_value(false);
pros::Imu IMU(19);
//IMU.reset(true);
// IMU.reset(true);
IMU.tare();
pros::delay(200);
@ -247,7 +306,8 @@ void autonomous() {
std::printf("yaw: %f\n", yaw);
// double turn = -92 - yaw;
double turn = 45 - yaw;
std:printf("turn: %f\n", turn);
std:
printf("turn: %f\n", turn);
drive->setMaxVelocity(300);
drive->turnAngle(turn * 1_deg);
drive->moveDistanceAsync(4.1_ft);
@ -316,7 +376,7 @@ void autonomous() {
(900 -
temp), // pull.moveRelative((1800
//-
//std::fmod(pull.getPosition(), 1800)),
// std::fmod(pull.getPosition(), 1800)),
10000000);
reqtopull = false;
@ -394,9 +454,9 @@ void autonomous() {
funnypiston.set_value(true);
pros::delay(500);
auto starttime = Timer().millis();
while (Timer().millis() < starttime + 1.5_s ) {
drive->getModel()->curvature(-12000 , IMU.get_rotation() * -0.04);
auto starttime = Timer().millis();
while (Timer().millis() < starttime + 1.5_s) {
drive->getModel()->curvature(-12000, IMU.get_rotation() * -0.04);
// printf("%i\n", distforward.get());
pros::delay(10);
@ -406,56 +466,57 @@ void autonomous() {
funnypiston.set_value(true);
pros::delay(500);
drive->moveDistance(1_in);
drive->moveDistance(1_in);
// drive->turnAngle(15_deg);
//drive->moveDistance(-3.8_ft);
//drive->turnAngle(90_deg);
bool imuholdarray[10];
// drive->moveDistance(-3.8_ft);
// drive->turnAngle(90_deg);
bool imuholdarray[10];
while (!is_held(imuholdarray, (abs(68.0 - IMU.get_rotation()) < 1)) ) {
drive->getModel()->rotate((68.0 - IMU.get_rotation()) * 0.008 );
pros::delay(10);
}
while (!is_held(imuholdarray, (abs(68.0 - IMU.get_rotation()) < 1))) {
drive->getModel()->rotate((68.0 - IMU.get_rotation()) * 0.008);
pros::delay(10);
}
drive->getModel()->stop();
drive->getModel()->stop();
funnypiston.set_value(false);
funnypiston.set_value(false);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
funnypiston.set_value(true);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
funnypiston.set_value(false);
drive->turnAngle(45_deg);
funnypiston.set_value(true);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
drive->moveDistance(1_ft);
funnypiston.set_value(false);
drive->turnAngle(45_deg);
drive->moveDistance(-2_ft);
drive->moveDistance(1_ft);
}
if (autonpick == 6) {
drive->setMaxVelocity(600);
float x = 2;
drive->moveDistance(x * -1_ft);
pros::delay(500);
float x = -2.7;
drive->moveDistanceAsync(x * 1_ft);
pros::delay(2500);
drive->moveDistance(0.5_ft);
}
if (autonpick == 7) {
drive->moveDistance(-1_ft);
piston.set_value(true);
pros::delay(44500);
drive->moveDistance(1_ft);
piston.set_value(true);
drive->turnAngle(-45_deg);
funnypiston.set_value(true);
pros::delay(500);
drive->moveDistance(6.5_ft);
drive->turnAngle(-45_deg);
drive->moveDistance(1_ft);
drive->moveDistance(-1_ft);
drive->moveDistance(1_ft);
drive->moveDistance(-1_ft);
}
if (autonpick == 8) {
if (autonpick == 7) {
drive->moveDistance(-1_ft);
piston.set_value(true);
pros::delay(44500);
drive->moveDistance(1_ft);
piston.set_value(false);
drive->turnAngle(-45_deg);
funnypiston.set_value(true);
pros::delay(500);
drive->moveDistance(7.5_ft);
drive->turnAngle(-45_deg);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
}
if (autonpick == 8) {
pros::Distance distforward(17);
// drive->moveDistanceAsync(500_ft);
drive->getModel()->setBrakeMode(okapi::AbstractMotor::brakeMode::hold);
@ -474,9 +535,9 @@ void autonomous() {
funnypiston.set_value(true);
pros::delay(500);
auto starttime = Timer().millis();
while (Timer().millis() < starttime + 1.5_s ) {
drive->getModel()->curvature(-6000 , IMU.get_rotation() * -0.04);
auto starttime = Timer().millis();
while (Timer().millis() < starttime + 1.5_s) {
drive->getModel()->curvature(-6000, IMU.get_rotation() * -0.04);
// printf("%i\n", distforward.get());
pros::delay(10);
@ -486,36 +547,132 @@ void autonomous() {
funnypiston.set_value(true);
pros::delay(500);
drive->moveDistance(1_in);
drive->moveDistance(1_in);
// drive->turnAngle(15_deg);
//drive->moveDistance(-3.8_ft);
//drive->turnAngle(90_deg);
bool imuholdarray[10];
// drive->moveDistance(-3.8_ft);
// drive->turnAngle(90_deg);
bool imuholdarray[10];
while (!is_held(imuholdarray, (abs(70.0 - IMU.get_rotation()) < 1)) ) {
drive->getModel()->rotate((70.0 - IMU.get_rotation()) * 0.008 );
pros::delay(10);
}
while (!is_held(imuholdarray, (abs(70.0 - IMU.get_rotation()) < 1))) {
drive->getModel()->rotate((70.0 - IMU.get_rotation()) * 0.008);
pros::delay(10);
}
drive->getModel()->stop();
funnypiston.set_value(false);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
funnypiston.set_value(true);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
funnypiston.set_value(false);
// //drive->moveDistance(0_ft);
// pros::delay(300);
// drive->turnAngle(50_deg);
// pros::delay(300);
// drive->moveDistance(-1.5_ft);
}
if (autonpick == 9) {
piston.set_value(true);
pros::delay(300);
piston.set_value(false);
pros::Distance distforward(17);
// drive->moveDistanceAsync(500_ft);
drive->getModel()->setBrakeMode(okapi::AbstractMotor::brakeMode::hold);
// piston.set_value(true);
// NEED TO WRTIE IMU CENTER CODE
// update IMU each cycle to get true rotation
while (distforward.get() > 300) {
drive->getModel()->curvature(12000, IMU.get_rotation() * -0.04);
// printf("%i\n", distforward.get());
pros::delay(10);
}
drive->stop();
funnypiston.set_value(true);
pros::delay(500);
drive->setMaxVelocity(200);
drive->moveDistance(-1_in);
bool imuholdarray[10];
drive->setMaxVelocity(600);
// while (!is_held(imuholdarray, (abs(100.0 - IMU.get_rotation()) < 1))) {
// drive->getModel()->rotate((100.0 - IMU.get_rotation()) * 0.008);
// pros::delay(10);
// }
drive->turnAngle(100_deg);
drive->getModel()->stop();
funnypiston.set_value(false);
drive->moveDistanceAsync(2_ft);
pros::delay(1000);
drive->moveDistance(-1_ft);
while (!is_held(imuholdarray, (abs(-110.0 - IMU.get_rotation()) < 3))) {
drive->getModel()->rotate((-110.0 - IMU.get_rotation()) * 0.008);
pros::delay(10);
}
drive->getModel()->stop();
while (distforward.get() > 300) {
drive->getModel()->curvature(12000, (IMU.get_rotation()+110) * -0.04);
// printf("%i\n", distforward.get());
pros::delay(10);
}
drive->stop();
funnypiston.set_value(true);
pros::delay(500);
drive->moveDistance(-1_ft);
while (!is_held(imuholdarray, (abs(75.0 - IMU.get_rotation()) < 3))) {
drive->getModel()->rotate((75.0 - IMU.get_rotation()) * 0.008);
pros::delay(10);
}
drive->getModel()->stop();
funnypiston.set_value(false);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
drive->moveDistanceAsync(3_ft);
pros::delay(1000);
drive->moveDistance(-1_ft);
while (!is_held(imuholdarray, (abs(-70.0 - IMU.get_rotation()) < 3))) {
drive->getModel()->rotate((-70.0 - IMU.get_rotation()) * 0.008);
pros::delay(10);
}
drive->getModel()->stop();
drive->moveDistance(1_ft);
funnypiston.set_value(true);
drive->moveDistance(2_ft);
drive->moveDistance(-2_ft);
pros::delay(300);
drive->turnAngle(180_deg);
funnypiston.set_value(false);
// //drive->moveDistance(0_ft);
// pros::delay(300);
// drive->turnAngle(50_deg);
// pros::delay(300);
// drive->moveDistance(-1.5_ft);
}
drive->moveDistanceAsync(3_ft);
pros::delay(1000);
drive->moveDistanceAsync(-1_ft);
// piston.set_value(false);
}
}
/**
@ -694,6 +851,31 @@ void opcontrol() {
bool intakebool;
intakebool = false;
lv_fs_drv_t pcfs_drv; /*A driver descriptor*/
memset(&pcfs_drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/
pcfs_drv.file_size = sizeof(pc_file_t); /*Set up fields...*/
pcfs_drv.letter = 'S';
pcfs_drv.open = pcfs_open;
pcfs_drv.close = pcfs_close;
pcfs_drv.read = pcfs_read;
pcfs_drv.seek = pcfs_seek;
pcfs_drv.tell = pcfs_tell;
lv_fs_add_drv(&pcfs_drv);
lv_obj_clean(lv_scr_act());
lv_obj_t *img_var = lv_img_create(lv_scr_act(), NULL);
lv_obj_t *dog_var = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img_var, "S:/usd/raa.bin");
lv_obj_set_pos(img_var, 200, 0);
lv_obj_set_size(img_var, 200, 200);
lv_img_set_src(dog_var, "S:/usd/dog2.bin");
lv_obj_set_pos(dog_var, 200, 0);
lv_obj_set_size(dog_var, 200, 200);
while (true) {
// Tank drive with left and right sticks.
drive->getModel()->tank(controller.getAnalog(ControllerAnalog::leftY),
@ -753,6 +935,7 @@ void opcontrol() {
if (is_tapped(funnyarr, L2.isPressed())) {
funnypistonstatus = !funnypistonstatus;
lv_obj_set_hidden(dog_var, !funnypistonstatus);
}
if (is_tapped(upflaparr, R2.isPressed())) {