Skip to content

Commit

Permalink
Merge pull request #13 from PenguinEmpire/dev
Browse files Browse the repository at this point in the history
Dev to master
  • Loading branch information
ryan-blanchard authored Feb 20, 2018
2 parents 946f116 + 0fd9a62 commit b949b01
Show file tree
Hide file tree
Showing 2 changed files with 789 additions and 76 deletions.
64 changes: 51 additions & 13 deletions FRC2018/src/PenguinEmpire.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@
#include "MyJoystick.h"
#include "AHRS.h"

class Lidar {
public:
Lidar();
unsigned int AquireDistance(/*Timer**/);
private:
enum Address {ADDRESS_DEFAULT=0x62}; // default I2C bus address for the LIDAR Lite v2
enum Register {COMMAND=0x00, STATUS=0x01, DISTANCE_1_2=0x8f};
enum Command {ACQUIRE_DC_CORRECT=0x04};
enum NumberOfRegistersToRead {READ_1_REGISTER=0x01, READ_2_REGISTERS=0x02};
enum NumberOfRegistersToWrite {WRITE_1_REGISTER=0x01};
I2C* I2CBus;

bool Busy()
{
unsigned char Status[Lidar::READ_1_REGISTER];
unsigned char statusRegister[Lidar::WRITE_1_REGISTER];
statusRegister[Lidar::WRITE_1_REGISTER-1] = Lidar::STATUS;

/**********read status**********/
if ( I2CBus->WriteBulk(statusRegister, Lidar::WRITE_1_REGISTER)) {printf ( "WriteBulk status failed! line %d\n", __LINE__ ); return true;}
if ( I2CBus->ReadOnly(Lidar::READ_1_REGISTER, Status) ) {printf ( "ReadOnly status failed! line %d\n", __LINE__ ); return true;}
//printf("Status at line %d %0x, bit0=%0x\n", __LINE__, Status[0], Status[0] & (unsigned char)0x01);
return (Status[0] & (unsigned char)0x01); // bit 0 is LIDAR Lite v2 busy bit
};
};

class Robot : public IterativeRobot {
public:
Expand All @@ -26,8 +51,13 @@ class Robot : public IterativeRobot {
Compressor compressor;
DoubleSolenoid leftGearbox, rightGearbox, liftGearbox; // Gearbox shifters
DoubleSolenoid omniDropper;
Timer* timer;
DigitalInput* hallSensor;
Timer* mainTimer;
Timer* lidarTimer;
Lidar* lidar;
DigitalInput* bottomSensor;
DigitalInput* switchSensor;
DigitalInput* topSensor;
Encoder leftEnc, rightEnc;

// Values and Structures
bool leftSwitch; // Is our color on the left side of the switch?
Expand All @@ -39,17 +69,13 @@ class Robot : public IterativeRobot {
float current;
int latestYaw;
bool turnSetup;
bool comboLift;
bool comboDrive;

bool gl90, gr90, gl180, gr180;

int testStep;

enum FieldPosition { // Used for autonomous
leftPos,
centerPos,
rightPos
} fpos;

enum StepType { // Used for autonomous
reset,
encoderMove,
Expand Down Expand Up @@ -79,8 +105,20 @@ class Robot : public IterativeRobot {
// };

std::vector<std::vector<double>> autosteps;
std::vector<std::vector<double>> ll, lr, cl, cr, rl, rr;
int numsteps, curstep;
bool stepSetup, stepComplete;
int fpos;
std::string mode;

int lastLiftState;
bool haltLifter;
bool goingPastSwitch;

std::shared_ptr<NetworkTable> contour;
std::vector<double> centerX, centerY, area, width;

int dist;

// Stages

Expand All @@ -93,18 +131,18 @@ class Robot : public IterativeRobot {
void AutonomousInit();
void AutonomousPeriodic();
void CheckSide();
void CheckPos();
void LeftAuto();
void CenterAuto();
void RightAuto();
int CheckPos();
void RunSteps();
void ResetAll();
void StopMotors();
void AutoRunLifter(bool up, bool down);

// Teleoperated
void TeleopInit();
void TeleopPeriodic();
void SetLeftSpeed(double speed);
void SetRightSpeed(double speed);
void StopMotors();
void StopDriveMotors();
void TankDrive();
void Gyro90L(bool btn);
void Gyro90R(bool btn);
Expand Down
Loading

0 comments on commit b949b01

Please sign in to comment.