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

Commit 60b36a7

Browse files
committed
Update grabber class based on new info from electrical/mech
1 parent 71561e6 commit 60b36a7

File tree

4 files changed

+93
-31
lines changed

4 files changed

+93
-31
lines changed

Safety/AttitudeManager/Src/attitudeManagerInterface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
#include "attitudeManager.hpp"
44
#include "PPM.hpp"
55
#include "PWM.hpp"
6+
#include "grabber.hpp"
67

78
attitudeManager *attMng;
89

910
void AttitudeManagerInterfaceInit(void) {
1011
PPMChannel *ppm = new PPMChannel(MAX_PPM_CHANNELS);
1112
PWMChannel *pwm = new PWMChannel();
12-
uint8_t grabberChannel = 5; //TODO: What channel?
13-
Grabber *grabber = &Grabber::getInstance(grabberChannel);
13+
Grabber *grabber = &Grabber::getInstance(4,5,6,7,pwm); //TODO: What output channel?
1414
attMng = new attitudeManager(ppm, pwm, grabber);
1515
}
1616

Safety/AttitudeManager/Src/attitudeStateClasses.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ void PeripheralControlMode::execute(attitudeManager* attitudeMgr)
324324
{
325325
PPM_Instructions_t *teleopInstructions = fetchInstructionsMode::GetTeleopInstructions();
326326
if (teleopInstructions->PPMValues[attitudeMgr->grabber->ppmChannel] > 50)
327-
attitudeMgr->grabber->close();
327+
attitudeMgr->grabber->close(50);
328328
else
329-
attitudeMgr->grabber->open();
329+
attitudeMgr->grabber->open(50);
330330
attitudeMgr->setState(fetchInstructionsMode::getInstance());
331331
}
332332

Safety/Inc/grabber.hpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,51 @@
77
/* Includes ------------------------------------------------------------------*/
88

99
#include "stm32f0xx.h"
10+
#include "PWM.hpp"
1011
// #include <stdint.h>
1112
// #include "../boardfiles/Inc/i2c.h"
1213

1314
/* Exported functions prototypes ---------------------------------------------*/
1415

1516
class Grabber {
1617
public:
17-
static Grabber& getInstance(uint8_t GPIO_Channel);
18+
static Grabber& getInstance(uint8_t grabber_pwm_channel_1,
19+
uint8_t grabber_pwm_channel_2,
20+
uint8_t crane_pwm_channel_1,
21+
uint8_t crane_pwm_channel_2,
22+
PWMChannel *pwm);
1823
Grabber(const Grabber*)=delete;
1924

20-
void open();
21-
void close();
25+
void open(uint8_t speed);
26+
void close(uint8_t speed);
2227

23-
uint8_t ppmChannel = 5; // TODO: What channel?
28+
void crane_brake();
29+
void crane_coast();
30+
void lower(uint8_t speed);
31+
void raise(uint8_t speed);
32+
33+
const uint8_t ppmChannel = 5; // TODO: What channel?
2434

2535
private:
2636
Grabber() {};
27-
Grabber(uint8_t GPIO_Channel);
28-
29-
GPIO_TypeDef *gpio = GPIOC; // TODO: Is this the right one?
37+
Grabber(uint8_t grabber_pwm_channel_1,
38+
uint8_t grabber_pwm_channel_2,
39+
uint8_t crane_pwm_channel_1,
40+
uint8_t crane_pwm_channel_2,
41+
PWMChannel *pwm) :
42+
grabber_channel_1(grabber_pwm_channel_1),
43+
grabber_channel_2(grabber_pwm_channel_2),
44+
crane_channel_1(grabber_pwm_channel_1),
45+
crane_channel_2(grabber_pwm_channel_2),
46+
pwm(*pwm) {}
3047

3148
bool isOpen = false;
32-
uint8_t channel = 0;
49+
bool isLowered = false;
50+
const uint8_t grabber_channel_1 = 0;
51+
const uint8_t grabber_channel_2 = 0;
52+
const uint8_t crane_channel_1 = 0;
53+
const uint8_t crane_channel_2 = 0;
54+
PWMChannel pwm;
3355
};
3456
#endif /* GRABBER_HPP */
3557

Safety/Src/grabber.cpp

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,73 @@
1111

1212
/* Public Methods ---------------------------------------------------------*/
1313

14-
Grabber& Grabber::getInstance(const uint8_t GPIO_Channel){
15-
static Grabber singleton(GPIO_Channel);
14+
Grabber& Grabber::getInstance( uint8_t grabber_pwm_channel_1,
15+
uint8_t grabber_pwm_channel_2,
16+
uint8_t crane_pwm_channel_1,
17+
uint8_t crane_pwm_channel_2,
18+
PWMChannel *pwm) {
19+
static Grabber singleton( grabber_pwm_channel_1,
20+
grabber_pwm_channel_2,
21+
crane_pwm_channel_1,
22+
crane_pwm_channel_2,
23+
pwm);
1624
return singleton;
1725
}
1826

19-
void Grabber::open() {
20-
if (!this->isOpen) {
21-
HAL_GPIO_WritePin(this->gpio, this->channel, GPIO_PIN_RESET);
27+
// Grabber lowering is controlled based on this table:
28+
// https://cdn-shop.adafruit.com/product-files/3190/drv8871.pdf
29+
// DRV8871 - Section 7.3.1
30+
// === H-Bridge Control ===
31+
// | IN1 | IN2 | OUT1 | OUT2 | DESCRIPTION
32+
// |-----|-----|--------|--------|-------------
33+
// | 0 | 0 | High-Z | High-Z | Coast; H-bridge disabled to High-Z (sleep entered after 1 ms)
34+
// | 0 | 1 | L | H | Reverse (Current OUT2 --> OUT1)
35+
// | 1 | 0 | H | L | Forward (Current OUT1 --> OUT2)
36+
// | 1 | 1 | L | L | Brake; low-side slow decay
37+
38+
void Grabber::crane_brake() {
39+
pwm.set(this->crane_channel_1, 100);
40+
pwm.set(this->crane_channel_2, 100);
41+
}
42+
void Grabber::crane_coast() {
43+
pwm.set(this->crane_channel_1, 0);
44+
pwm.set(this->crane_channel_2, 0);
45+
}
46+
// obviously this is not instant, and we probably need a callback once the device
47+
// is finished lowering to set the motor into brake mode and update its state
48+
// Unfortunately I dont know what that will look like... It could very well be time based
49+
// need more details from Mech/Electrical
50+
void Grabber::lower(uint8_t speed) {
51+
if (!this->isLowered) {
52+
pwm.set(this->crane_channel_1, speed);
53+
pwm.set(this->crane_channel_2, 0);
54+
this->isLowered = true;
55+
}
56+
}
57+
void Grabber::raise(uint8_t speed) {
58+
if (this->isLowered) {
59+
pwm.set(this->crane_channel_1, 0);
60+
pwm.set(this->crane_channel_2, speed);
61+
this->isLowered = false;
2262
}
2363
}
2464

25-
void Grabber::close() {
65+
66+
//TODO: Still need data from electrical on the input to the motor driver,
67+
// hopefully it is similar to the above
68+
void Grabber::close(uint8_t speed) {
69+
if (!this->isOpen) {
70+
pwm.set(this->grabber_channel_1, speed);
71+
pwm.set(this->grabber_channel_2, 0);
72+
this->isOpen = true;
73+
}
74+
}
75+
void Grabber::open(uint8_t speed) {
2676
if (this->isOpen) {
27-
HAL_GPIO_WritePin(this->gpio, this->channel, GPIO_PIN_SET);
77+
pwm.set(this->grabber_channel_1, 0);
78+
pwm.set(this->grabber_channel_2, speed);
79+
this->isOpen = false;
2880
}
2981
}
3082

3183
/* Private methods ---------------------------------------------------------*/
32-
Grabber::Grabber(uint8_t GPIO_Channel) {
33-
this->channel = GPIO_Channel;
34-
GPIO_InitTypeDef GPIO_InitStruct; //TODO: It might be better to init this in gpio.c. Also confirm these settings.
35-
GPIO_InitStruct.Pin = this->channel;
36-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
37-
GPIO_InitStruct.Pull = GPIO_NOPULL;
38-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
39-
HAL_GPIO_Init(this->gpio, &GPIO_InitStruct);
40-
HAL_GPIO_WritePin(this->gpio, this->channel, GPIO_PIN_RESET);
41-
42-
};
43-
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)