Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Update grabber controls & add use output for purchased driver board
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan-B committed Apr 27, 2022
1 parent 60b36a7 commit 849721b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
23 changes: 19 additions & 4 deletions Safety/AttitudeManager/Src/attitudeStateClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,26 @@ bool DisarmMode:: isArmed()

void PeripheralControlMode::execute(attitudeManager* attitudeMgr)
{
const uint8_t speed = 10;
PPM_Instructions_t *teleopInstructions = fetchInstructionsMode::GetTeleopInstructions();
if (teleopInstructions->PPMValues[attitudeMgr->grabber->ppmChannel] > 50)
attitudeMgr->grabber->close(50);
else
attitudeMgr->grabber->open(50);
const uint8_t &clawInput = teleopInstructions->PPMValues[attitudeMgr->grabber->ppmClawChannel];
const uint8_t &craneInput = teleopInstructions->PPMValues[attitudeMgr->grabber->ppmCraneChannel];

if (clawInput < 30)
attitudeMgr->grabber->close(speed);
else if (clawInput < 70)
attitudeMgr->grabber->brake();
else
attitudeMgr->grabber->open(speed);

if (craneInput < 30)
attitudeMgr->grabber->lower(speed);
else if (craneInput < 70)
attitudeMgr->grabber->crane_brake();
else
attitudeMgr->grabber->raise(speed);


attitudeMgr->setState(fetchInstructionsMode::getInstance());
}

Expand Down
6 changes: 3 additions & 3 deletions Safety/Inc/grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Grabber {
PWMChannel *pwm);
Grabber(const Grabber*)=delete;

void brake();
void open(uint8_t speed);
void close(uint8_t speed);

Expand All @@ -30,7 +31,8 @@ class Grabber {
void lower(uint8_t speed);
void raise(uint8_t speed);

const uint8_t ppmChannel = 5; // TODO: What channel?
const uint8_t ppmCraneChannel = 6; // TODO: What channel?
const uint8_t ppmClawChannel = 7; // TODO: What channel?

private:
Grabber() {};
Expand All @@ -45,8 +47,6 @@ class Grabber {
crane_channel_2(grabber_pwm_channel_2),
pwm(*pwm) {}

bool isOpen = false;
bool isLowered = false;
const uint8_t grabber_channel_1 = 0;
const uint8_t grabber_channel_2 = 0;
const uint8_t crane_channel_1 = 0;
Expand Down
37 changes: 15 additions & 22 deletions Safety/Src/grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,30 @@ void Grabber::crane_coast() {
// is finished lowering to set the motor into brake mode and update its state
// Unfortunately I dont know what that will look like... It could very well be time based
// need more details from Mech/Electrical
// Update: This will just rely on pilot visual unless otherwise required
void Grabber::lower(uint8_t speed) {
if (!this->isLowered) {
pwm.set(this->crane_channel_1, speed);
pwm.set(this->crane_channel_2, 0);
this->isLowered = true;
}
pwm.set(this->crane_channel_1, speed);
pwm.set(this->crane_channel_2, 0);
}
void Grabber::raise(uint8_t speed) {
if (this->isLowered) {
pwm.set(this->crane_channel_1, 0);
pwm.set(this->crane_channel_2, speed);
this->isLowered = false;
}
pwm.set(this->crane_channel_1, 0);
pwm.set(this->crane_channel_2, speed);
}


//TODO: Still need data from electrical on the input to the motor driver,
// hopefully it is similar to the above

// Using https://media.digikey.com/pdf/Data%20Sheets/Seeed%20Technology/105090004_Web.pdf
void Grabber::brake() {
pwm.set(this->grabber_channel_1, 0);
pwm.set(this->grabber_channel_2, 0);
}
void Grabber::close(uint8_t speed) {
if (!this->isOpen) {
pwm.set(this->grabber_channel_1, speed);
pwm.set(this->grabber_channel_2, 0);
this->isOpen = true;
}
pwm.set(this->grabber_channel_1, speed);
pwm.set(this->grabber_channel_2, 0);
}
void Grabber::open(uint8_t speed) {
if (this->isOpen) {
pwm.set(this->grabber_channel_1, 0);
pwm.set(this->grabber_channel_2, speed);
this->isOpen = false;
}
pwm.set(this->grabber_channel_1, 0);
pwm.set(this->grabber_channel_2, speed);
}

/* Private methods ---------------------------------------------------------*/

0 comments on commit 849721b

Please sign in to comment.