|  | 
| 11 | 11 | 
 | 
| 12 | 12 | /* Public Methods  ---------------------------------------------------------*/ | 
| 13 | 13 | 
 | 
| 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);  | 
| 16 | 24 |   return singleton;  | 
| 17 | 25 | } | 
| 18 | 26 | 
 | 
| 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; | 
| 22 | 62 | 	} | 
| 23 | 63 | } | 
| 24 | 64 | 
 | 
| 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) { | 
| 26 | 76 | 	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; | 
| 28 | 80 | 	} | 
| 29 | 81 | } | 
| 30 | 82 | 
 | 
| 31 | 83 | /* 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