First I changed the names for the mechanisms to match the current robot setup. I then made a new header file for the mechansims and a new cpp file for the mechanisms. The mechanisms now work the same way a piston works by allowing you to call the functions and input all the different variables inline. I also had to comment out all the old rotation code because of the changed names and not actually useing them, for now i'm just going to keep all the code where it is so I can look back on it for the future.
This commit is contained in:
1 parent
24ee947fd5
commit
94f88d09d6
11 files changed
+370
-84
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "api.h"
|
||||
#include "pros/adi.hpp"
|
||||
#include "pros/motors.hpp"
|
||||
#include "pros/motor_group.hpp"
|
||||
|
||||
namespace ez {
|
||||
|
||||
enum class ControlPeriodM {
|
||||
driver,
|
||||
auton
|
||||
};
|
||||
|
||||
enum class ControllerM {
|
||||
master,
|
||||
slave
|
||||
};
|
||||
|
||||
enum class ButtonsM {
|
||||
arrow_buttons,
|
||||
Y_B_buttons,
|
||||
left_shoulder_buttons,
|
||||
right_shoulder_buttons
|
||||
};
|
||||
|
||||
enum class MotorGroups {
|
||||
lift_MG,
|
||||
claw_M,
|
||||
roller_M
|
||||
};
|
||||
|
||||
class Mechanisms {
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
float fw_motor_speed = 0;
|
||||
float rev_motor_speed = 0;
|
||||
|
||||
Mechanisms();
|
||||
|
||||
void motor_control(enum ControlPeriodM, enum ControllerM, enum ButtonsM, enum MotorGroups, float fw_motor_speed, float rev_motor_speed);
|
||||
|
||||
float get_motor_speed();
|
||||
float set_motor_speed(float value);
|
||||
|
||||
};
|
||||
};
|
||||
@@ -33,7 +33,7 @@ namespace ez {
|
||||
* Enumeration to hold all the pistons avalable.
|
||||
*/
|
||||
enum class PistonsP {
|
||||
claw_piston
|
||||
PlaceHolderP
|
||||
};
|
||||
|
||||
class Pneumatics{
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace ez{
|
||||
void arm_auton_control(int pickState);
|
||||
void cycle_states();
|
||||
void reset_state();
|
||||
void hard_reset_arm(); // Once the arm hits a button the rotation sensor value is reset to 0
|
||||
void arm_control(); // Computes the velocity for the arm to move at.
|
||||
|
||||
void set_arm_kp(float _armKP);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "autons.hpp"
|
||||
#include "subsystems.hpp"
|
||||
#include "EZ-Template/rotation_mechanisms/rotation_calc.hpp"
|
||||
#include "EZ-Template/mechanisms.hpp"
|
||||
#include "EZ-Template/pneumatics.hpp"
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,20 +16,20 @@ inline pros::Controller slave(pros::E_CONTROLLER_PARTNER);
|
||||
/**
|
||||
* Declares mechinism motors and motor groups.
|
||||
*/
|
||||
inline pros::MotorGroup lift({15, -19});
|
||||
inline pros::MotorGroup wrist({1, 9});
|
||||
inline pros::Motor arm({6});
|
||||
inline pros::MotorGroup lift({-1, 2});
|
||||
inline pros::Motor claw({9});
|
||||
inline pros::Motor roller({5});
|
||||
|
||||
/**
|
||||
* Declares piston mechanisms.
|
||||
*/
|
||||
inline ez::Piston claw({'G',true});
|
||||
inline ez::Piston PlaceHolder({'G',true});
|
||||
|
||||
/**
|
||||
* Declare limit switches and other ADI sensors
|
||||
*/
|
||||
inline pros::ADIButton liftReset({'A'});
|
||||
inline pros::ADIButton armReset({'B'});
|
||||
//inline pros::ADIDigitalIn liftReset ('A');
|
||||
//inline pros::ADIDigitalIn armReset('B');
|
||||
|
||||
/**
|
||||
* Declares all sensors.
|
||||
@@ -38,11 +38,11 @@ inline pros::ADIButton armReset({'B'});
|
||||
*
|
||||
* [2] - Color sensors
|
||||
*/
|
||||
inline pros::Rotation liftRotation({17});
|
||||
inline pros::Rotation armRotation({8});
|
||||
inline pros::Rotation wristRotation({21});
|
||||
inline pros::Rotation liftRotation({0});
|
||||
inline pros::Rotation armRotation({0});
|
||||
inline pros::Rotation wristRotation({0});
|
||||
|
||||
inline pros::Optical colorSensorOne({18});
|
||||
inline pros::Optical colorSensorTwo({19});
|
||||
inline pros::Optical colorSensorOne({0});
|
||||
inline pros::Optical colorSensorTwo({0});
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,183 @@
|
||||
#include "main.h"
|
||||
#include "EZ-Template/pneumatics.hpp"
|
||||
|
||||
using namespace ez;
|
||||
|
||||
Mechanisms::Mechanisms(){}
|
||||
|
||||
void Mechanisms::motor_control(ControlPeriodM currPeriod, ControllerM currController, ButtonsM buttonsUsed, MotorGroups usedMotors, float fw_motor_speed, float rev_motor_speed) {
|
||||
|
||||
if (currPeriod == ControlPeriodM::driver) {
|
||||
switch (usedMotors)
|
||||
{
|
||||
case MotorGroups::lift_MG:
|
||||
|
||||
switch (currController)
|
||||
{
|
||||
case ControllerM::master:
|
||||
|
||||
switch (buttonsUsed)
|
||||
{
|
||||
case ButtonsM::arrow_buttons:
|
||||
if (master.get_digital(DIGITAL_RIGHT)) {
|
||||
lift.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_DOWN)) {
|
||||
lift.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
lift.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::Y_B_buttons:
|
||||
if (master.get_digital(DIGITAL_B)) {
|
||||
lift.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_Y)) {
|
||||
lift.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
lift.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::left_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
lift.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
lift.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
lift.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::right_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
lift.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
lift.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
lift.move(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//This is where the slave controller code goes for the lift
|
||||
}
|
||||
|
||||
case MotorGroups::claw_M:
|
||||
|
||||
switch (currController)
|
||||
{
|
||||
case ControllerM::master:
|
||||
|
||||
switch (buttonsUsed)
|
||||
{
|
||||
case ButtonsM::arrow_buttons:
|
||||
if (master.get_digital(DIGITAL_RIGHT)) {
|
||||
claw.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_DOWN)) {
|
||||
claw.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
claw.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::Y_B_buttons:
|
||||
if (master.get_digital(DIGITAL_B)) {
|
||||
claw.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_Y)) {
|
||||
claw.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
claw.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::left_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
claw.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
claw.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
claw.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::right_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
claw.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
claw.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
claw.move(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//This is where the slave controller code goes for the claw
|
||||
}
|
||||
|
||||
case MotorGroups::roller_M:
|
||||
|
||||
switch (currController)
|
||||
{
|
||||
case ControllerM::master:
|
||||
|
||||
switch (buttonsUsed)
|
||||
{
|
||||
case ButtonsM::arrow_buttons:
|
||||
if (master.get_digital(DIGITAL_RIGHT)) {
|
||||
roller.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_DOWN)) {
|
||||
roller.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
roller.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::Y_B_buttons:
|
||||
if (master.get_digital(DIGITAL_B)) {
|
||||
roller.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_Y)) {
|
||||
roller.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
roller.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::left_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
roller.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
roller.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
roller.move(0);
|
||||
}
|
||||
break;
|
||||
case ButtonsM::right_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
roller.move(fw_motor_speed);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
roller.move(rev_motor_speed);
|
||||
}
|
||||
else {
|
||||
roller.move(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//This is where the slave controller code goes for the roller
|
||||
}
|
||||
//More motors and motor group controls can be added here
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,46 +10,46 @@ void Pneumatics::control_piston(PistonsP activePiston, ControlPeriodP currPeriod
|
||||
if (currPeriod == ControlPeriodP::driver) {
|
||||
switch (activePiston)
|
||||
{
|
||||
case PistonsP::claw_piston:
|
||||
/*More code can go here if the claw piston is selected*/
|
||||
case PistonsP::PlaceHolderP:
|
||||
/*More code can go here if this piston is selected*/
|
||||
|
||||
switch (currController)
|
||||
{
|
||||
case ControllerP::master:
|
||||
/*More code can go here if we want to use the master controller*/
|
||||
/*More code can go here that uses the master controller*/
|
||||
|
||||
switch (buttonUsed)
|
||||
{
|
||||
case ButtonsP::arrow_buttons:
|
||||
if (master.get_digital(DIGITAL_RIGHT)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_DOWN)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
case ButtonsP::Y_B_buttons:
|
||||
if (master.get_digital(DIGITAL_Y)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_B)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
case ButtonsP::left_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
case ButtonsP::right_shoulder_buttons:
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -57,61 +57,59 @@ void Pneumatics::control_piston(PistonsP activePiston, ControlPeriodP currPeriod
|
||||
}
|
||||
break;
|
||||
case ControllerP::slave:
|
||||
|
||||
/*More code can go here that needs to use the slave controller*/
|
||||
switch (buttonUsed)
|
||||
{
|
||||
case ButtonsP::arrow_buttons:
|
||||
if (slave.get_digital(DIGITAL_RIGHT)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_DOWN)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
case ButtonsP::Y_B_buttons:
|
||||
if (slave.get_digital(DIGITAL_Y)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_B)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
case ButtonsP::left_shoulder_buttons:
|
||||
if (slave.get_digital(DIGITAL_L1)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_L2)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
case ButtonsP::right_shoulder_buttons:
|
||||
if (slave.get_digital(DIGITAL_R1)) {
|
||||
claw.set(true);
|
||||
PlaceHolder.set(true);
|
||||
}
|
||||
else if (slave.get_digital(DIGITAL_R2)) {
|
||||
claw.set(false);
|
||||
PlaceHolder.set(false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/*This is were more cases can go for the controller switch*/
|
||||
|
||||
/*This is were more cases can go for more controllers (which isn't allowed)*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
/*This is were more cases can go fot the piston selected switch*/
|
||||
/*This is were more cases can go for other pistons*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
switch (activePiston)
|
||||
{
|
||||
case PistonsP::claw_piston:
|
||||
case PistonsP::PlaceHolderP:
|
||||
/*code here*/
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#include "EZ-Template/rotation_mechanisms/rotation_calc.hpp"
|
||||
|
||||
using namespace ez;
|
||||
|
||||
/*
|
||||
LiftMech liftRangeAccess; // Lift object to use lift variables and functions
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
|||/
|
||||
ArmMech::ArmMech() {
|
||||
currArmState = 0;
|
||||
armTarget = 0;
|
||||
@@ -24,7 +24,7 @@ ArmMech::ArmMech() {
|
||||
* Input the controller being used
|
||||
* \param buttonUsed
|
||||
* Select the button config you want use
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::arm_driver_control(ControllerR currController, ButtonsR buttonUsed) {
|
||||
|
||||
switch (currController) // Switch that check which controller was selected
|
||||
@@ -36,37 +36,37 @@ void ArmMech::arm_driver_control(ControllerR currController, ButtonsR buttonUsed
|
||||
case ButtonsR::arrow_buttons:
|
||||
// If the arrow_buttons are selected run this code
|
||||
if (master.get_digital(DIGITAL_RIGHT)){
|
||||
arm.move(127);
|
||||
//arm.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_DOWN)) {
|
||||
arm.move(-127);
|
||||
//arm.move(-127);
|
||||
}
|
||||
break;
|
||||
case ButtonsR::Y_B_buttons:
|
||||
// If the Y_B_buttons are selected run this code
|
||||
if (master.get_digital(DIGITAL_Y)){
|
||||
arm.move(127);
|
||||
//arm.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_B)) {
|
||||
arm.move(-127);
|
||||
//arm.move(-127);
|
||||
}
|
||||
break;
|
||||
case ButtonsR::left_shoulder_buttons:
|
||||
// If the left-shoulder_buttons are selected run this code
|
||||
if (master.get_digital(DIGITAL_L1)){
|
||||
arm.move(127);
|
||||
//arm.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
arm.move(-127);
|
||||
//arm.move(-127);
|
||||
}
|
||||
break;
|
||||
case ButtonsR::right_shoulder_buttons:
|
||||
// If the right_shoulder_buttons are selected run this code
|
||||
if (master.get_digital(DIGITAL_R1)){
|
||||
arm.move(127);
|
||||
//arm.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
arm.move(-127);
|
||||
//arm.move(-127);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -127,7 +127,7 @@ void ArmMech::arm_driver_control(ControllerR currController, ButtonsR buttonUsed
|
||||
*
|
||||
* \param pickState
|
||||
* Variable to move the arm. Input: 1 to move or Input: 0 which won't move it
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::arm_auton_control(int pickState) {
|
||||
liftRangeAccess.lift_range_finder(); // Returns a value 0 - 3 based on where the lift is currently
|
||||
|
||||
@@ -177,7 +177,7 @@ void ArmMech::arm_auton_control(int pickState) {
|
||||
|
||||
/**
|
||||
* Function to cycle through each value in the array
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::cycle_states() {
|
||||
liftRangeAccess.lift_range_finder(); // Returns a value 0 - 3 based on were the lift is currently
|
||||
|
||||
@@ -212,7 +212,7 @@ void ArmMech::cycle_states() {
|
||||
|
||||
/**
|
||||
* Function reset the array indexer to zero
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::reset_state() {
|
||||
currArmState = 0;
|
||||
|
||||
@@ -222,13 +222,19 @@ void ArmMech::reset_state() {
|
||||
}
|
||||
}
|
||||
|
||||
void ArmMech::hard_reset_arm() {
|
||||
if (armReset.get_value() == 1) {
|
||||
armRotation.reset_position();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to set the velocity of the arm
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::arm_control() {
|
||||
armError = armTarget - armRotation.get_position(); // Sets the error value
|
||||
armVelocity = get_arm_kp() * armError; // Sets the velocity
|
||||
arm.move(armVelocity); // moves the arm
|
||||
//arm.move(armVelocity); // moves the arm
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -242,7 +248,7 @@ void ArmMech::arm_control() {
|
||||
* The array used if the lift is at level three
|
||||
* \param _levelFourArmStates
|
||||
* The array used if the lift is at level four
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::set_state_values(std::vector<int> _levelOneArmStates, std::vector<int> _levelTwoArmStates, std::vector<int> _levelThreeArmStates, std::vector<int> _levelFourArmStates) {
|
||||
levelOneArmStates = _levelOneArmStates;
|
||||
levelTwoArmStates = _levelTwoArmStates;
|
||||
@@ -254,7 +260,7 @@ void ArmMech::set_state_values(std::vector<int> _levelOneArmStates, std::vector<
|
||||
*
|
||||
* \param _armKP
|
||||
* The input value that is then used for the kp value
|
||||
*/
|
||||
|||/
|
||||
void ArmMech::set_arm_kp(float _armKP) {
|
||||
armKP = _armKP;
|
||||
}
|
||||
@@ -266,4 +272,5 @@ int ArmMech::get_arm_state() {
|
||||
return selectedStates[currArmState];
|
||||
}
|
||||
int ArmMech::get_num_arm_states() {return numArmStates;}
|
||||
float ArmMech::get_arm_kp() {return armKP;}
|
||||
float ArmMech::get_arm_kp() {return armKP;}
|
||||
*/
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "EZ-Template/rotation_mechanisms/rotation_calc.hpp"
|
||||
|
||||
using namespace ez;
|
||||
|
||||
/*
|
||||
ArmMech armObjRange;
|
||||
|
||||
LiftMech::LiftMech() {
|
||||
@@ -188,4 +188,5 @@ int LiftMech::get_lift_state() {
|
||||
}
|
||||
}
|
||||
int LiftMech::get_num_lift_states() {return numLiftStates;}
|
||||
float LiftMech::get_lift_kp() {return liftKP;}
|
||||
float LiftMech::get_lift_kp() {return liftKP;}
|
||||
*/
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "EZ-Template/rotation_mechanisms/rotation_calc.hpp"
|
||||
|
||||
using namespace ez;
|
||||
|
||||
/*
|
||||
WristMech::WristMech() {
|
||||
wristError = 0;
|
||||
wristVelocity = 0;
|
||||
@@ -100,7 +100,7 @@ void WristMech::reset_state() {
|
||||
void WristMech::wrist_control() {
|
||||
wristError = wristTarget - wristRotation.get_position();
|
||||
wristVelocity = get_wrist_kp() * wristError;
|
||||
wrist.move(wristVelocity);
|
||||
//wrist.move(wristVelocity);
|
||||
}
|
||||
|
||||
int WristMech::get_wrist_state() {
|
||||
@@ -113,4 +113,5 @@ float WristMech::get_wrist_kp() {return wristKP;}
|
||||
|
||||
void WristMech::set_wrist_kp(float _wristKP) {
|
||||
wristKP = _wristKP;
|
||||
}
|
||||
}
|
||||
*/
|
||||
+68
-23
@@ -4,10 +4,10 @@
|
||||
// Chassis constructor
|
||||
ez::Drive chassis(
|
||||
// These are your drive motors, the first motor is used for sensing!
|
||||
{12, 14}, // Left Chassis Ports (negative port will reverse it!)
|
||||
{-11, -13}, // Right Chassis Ports (negative port will reverse it!)
|
||||
{-11, -12}, // Left Chassis Ports (negative port will reverse it!)
|
||||
{13, 14}, // Right Chassis Ports (negative port will reverse it!)
|
||||
|
||||
21, // IMU Port
|
||||
6, // IMU Port
|
||||
3.25, // Wheel Diameter (Remember, 4" wheels without screw holes are actually 4.125!)
|
||||
360.0); // Wheel RPM = cartridge * (motor gear / wheel gear)
|
||||
|
||||
@@ -16,22 +16,23 @@ ez::Drive chassis(
|
||||
// - you should get positive values on the encoders going FORWARD and RIGHT
|
||||
// - `2.75` is the wheel diameter
|
||||
// - `4.0` is the distance from the center of the wheel to the center of the robot
|
||||
ez::tracking_wheel horiz_tracker(8, 2.75, 4.0); // This tracking wheel is perpendicular to the drive wheels
|
||||
// ez::tracking_wheel vert_tracker(9, 2.75, 4.0); // This tracking wheel is parallel to the drive wheels
|
||||
ez::tracking_wheel horiz_tracker(16, 3.25, 4.0); // This tracking wheel is perpendicular to the drive wheels
|
||||
ez::tracking_wheel vert_tracker(17, 3.25, 2.0); // This tracking wheel is parallel to the drive wheels
|
||||
|
||||
// Default Objects
|
||||
Pneumatics pistonControl;
|
||||
ArmMech armObj;
|
||||
Mechanisms motorControl;
|
||||
//ArmMech armObj;
|
||||
|
||||
// Lift constructor
|
||||
LiftMech liftObj(
|
||||
/*LiftMech liftObj(
|
||||
|
||||
{0, 63194, 94246, 139878}, 4);
|
||||
|
||||
// Wrist constructor
|
||||
WristMech wristObj(
|
||||
|
||||
{0, -14529}, 2);
|
||||
{0, -14529}, 2);*/
|
||||
|
||||
/**
|
||||
* Runs initialization code. This occurs as soon as the program is started.
|
||||
@@ -45,7 +46,7 @@ void initialize() {
|
||||
|
||||
pros::delay(500); // Stop the user from doing anything while legacy ports configure
|
||||
|
||||
armObj.set_state_values(
|
||||
/*armObj.set_state_values(
|
||||
{0, -5642},
|
||||
{0, -22702},
|
||||
{0, -19740},
|
||||
@@ -60,25 +61,25 @@ void initialize() {
|
||||
|
||||
armRotation.reset_position();
|
||||
liftRotation.reset_position();
|
||||
wristRotation.reset_position();
|
||||
wristRotation.reset_position();*/
|
||||
|
||||
pros::Task liftControlTasck([&]{
|
||||
/*pros::Task liftControlTasck([&]{
|
||||
while (true) {
|
||||
armObj.arm_control();
|
||||
liftObj.lift_control();
|
||||
wristObj.wrist_control();
|
||||
pros::delay(10);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
|
||||
// Look at your horizontal tracking wheel and decide if it's in front of the midline of your robot or behind it
|
||||
// - change `back` to `front` if the tracking wheel is in front of the midline
|
||||
// - ignore this if you aren't using a horizontal tracker
|
||||
// chassis.odom_tracker_back_set(&horiz_tracker);
|
||||
chassis.odom_tracker_front_set(&horiz_tracker);
|
||||
// Look at your vertical tracking wheel and decide if it's to the left or right of the center of the robot
|
||||
// - change `left` to `right` if the tracking wheel is to the right of the centerline
|
||||
// - ignore this if you aren't using a vertical tracker
|
||||
// chassis.odom_tracker_left_set(&vert_tracker);
|
||||
chassis.odom_tracker_right_set(&vert_tracker);
|
||||
|
||||
// Configure your chassis controls
|
||||
chassis.opcontrol_curve_buttons_toggle(true); // Enables modifying the controller curve with buttons on the joysticks
|
||||
@@ -281,22 +282,64 @@ void ez_template_extras() {
|
||||
void opcontrol() {
|
||||
// This is preference to what you like to drive on
|
||||
chassis.drive_brake_set(MOTOR_BRAKE_HOLD);
|
||||
|
||||
lift.set_brake_mode(MOTOR_BRAKE_HOLD);
|
||||
claw.set_brake_mode(MOTOR_BRAKE_HOLD);
|
||||
roller.set_brake_mode(MOTOR_BRAKE_HOLD);
|
||||
|
||||
while (true) {
|
||||
// Gives you some extras to make EZ-Template ezier
|
||||
ez_template_extras();
|
||||
|
||||
// Call custom drive functions here
|
||||
pistonControl.control_piston(PistonsP::claw_piston, ControlPeriodP::driver,
|
||||
ControllerP::slave, ButtonsP::arrow_buttons);
|
||||
pistonControl.control_piston(PistonsP::PlaceHolderP, ControlPeriodP::driver,
|
||||
ControllerP::master, ButtonsP::arrow_buttons);
|
||||
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::right_shoulder_buttons,
|
||||
MotorGroups::lift_MG, 127, -127);
|
||||
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::left_shoulder_buttons,
|
||||
MotorGroups::claw_M, -127, 127);
|
||||
motorControl.motor_control(ControlPeriodM::driver, ControllerM::master, ButtonsM::Y_B_buttons,
|
||||
MotorGroups::roller_M, 127, 0);
|
||||
|
||||
// Basic control scheme
|
||||
/*arm.set_brake_mode(MOTOR_BRAKE_HOLD);
|
||||
if (master.get_digital(DIGITAL_L1)) {
|
||||
arm.move(90);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_L2)) {
|
||||
arm.move(-90);
|
||||
}
|
||||
else {
|
||||
arm.brake();
|
||||
}
|
||||
|
||||
lift.set_brake_mode(MOTOR_BRAKE_HOLD);
|
||||
if (master.get_digital(DIGITAL_R1)) {
|
||||
lift.move(127);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_R2)) {
|
||||
lift.move(-127);
|
||||
}
|
||||
else {
|
||||
lift.brake();
|
||||
}
|
||||
|
||||
wrist.set_brake_mode(MOTOR_BRAKE_HOLD);
|
||||
if (master.get_digital(DIGITAL_A)) {
|
||||
wrist.move(20);
|
||||
}
|
||||
else if (master.get_digital(DIGITAL_B)) {
|
||||
wrist.move(-20);
|
||||
}
|
||||
else {
|
||||
wrist.brake();
|
||||
}
|
||||
//armObj.arm_driver_control(ControllerR::master, ButtonsR::left_shoulder_buttons);
|
||||
//liftObj.lift_driver_control(ControllerR::master, ButtonsR::right_shoulder_buttons);
|
||||
|
||||
armObj.arm_driver_control(ControllerR::slave, ButtonsR::left_shoulder_buttons);
|
||||
liftObj.lift_driver_control(ControllerR::slave, ButtonsR::right_shoulder_buttons);
|
||||
wristObj.wrist_driver_control(ControllerR::slave, ButtonsR::Y_B_buttons);
|
||||
//wristObj.rotate_wrist(90);
|
||||
//armObj.arm_driver_control(ControllerR::slave, ButtonsR::left_shoulder_buttons);
|
||||
//liftObj.lift_driver_control(ControllerR::slave, ButtonsR::right_shoulder_buttons);
|
||||
//wristObj.wrist_driver_control(ControllerR::slave, ButtonsR::Y_B_buttons);
|
||||
//wristObj.rotate_wrist(90);*/
|
||||
|
||||
chassis.opcontrol_arcade_standard(ez::SPLIT); // Standard split arcade
|
||||
// chassis.opcontrol_tank(); // Tank control
|
||||
@@ -305,10 +348,12 @@ void opcontrol() {
|
||||
// chassis.opcontrol_arcade_flipped(ez::SINGLE); // Flipped single arcade
|
||||
|
||||
// Terminal debugging
|
||||
std::cout << "Arm rotation sensor value: " << "\033[31m" << armRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
/*std::cout << "Arm rotation sensor value: " << "\033[31m" << armRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
std::cout << "Lift rotation sensor value: " << "\033[32m" << liftRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
std::cout << "Wrist rotation sensor value: " << "\033[33m" << wristRotation.get_position() << " cdg" << "mm\033[0m" << std::endl;
|
||||
|
||||
std::cout << "Arm limit switch value: " << "\033[34m" << armReset.get_value() << "mm\033[0m" << std::endl;*/
|
||||
|
||||
///pros::delay(250);
|
||||
pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations! Keep this ez::util::DELAY_TIME
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user