-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ZXMB5210 Magnetorquer control lib!
- Loading branch information
Showing
6 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "ZXMB5210.h" | ||
|
||
/* | ||
* @brief Construct a new instance. | ||
* | ||
* @param[in] fwd Forward pin | ||
* @param[in] rev The reverse pin | ||
* @param[in] buck The buck enable pin, must be high to drive motor | ||
*/ | ||
ZXMB5210::ZXMB5210(uint8_t fwd, uint8_t rev, uint8_t buck){ | ||
this->fwd_pin = fwd; | ||
this->rev_pin = rev; | ||
this->buck_enable = buck; | ||
|
||
pinMode(this->buck_enable, OUTPUT); | ||
digitalWrite(this->buck_enable, LOW); | ||
|
||
pinMode(this->fwd_pin, OUTPUT); | ||
digitalWrite(this->fwd_pin, LOW); | ||
|
||
pinMode(this->rev_pin, OUTPUT); | ||
digitalWrite(this->fwd_pin, LOW); | ||
|
||
} | ||
|
||
/** | ||
* @brief Constructs a new instance. Doesn't set the state of the buck converter. | ||
* | ||
* @param[in] fwd Forward pin | ||
* @param[in] rev The reverse pin | ||
*/ | ||
ZXMB5210::ZXMB5210(uint8_t fwd, uint8_t rev){ | ||
this->fwd_pin = fwd; | ||
this->rev_pin = rev; | ||
|
||
pinMode(this->fwd_pin, OUTPUT); | ||
digitalWrite(this->fwd_pin, LOW); | ||
|
||
pinMode(this->rev_pin, OUTPUT); | ||
digitalWrite(this->fwd_pin, LOW); | ||
|
||
} | ||
|
||
/** | ||
* @brief drive the motor forward | ||
*/ | ||
void ZXMB5210::fwd(void){ | ||
if(this->buck_enable < 255){ // send power to the magnetorquers | ||
digitalWrite(this->buck_enable, HIGH); | ||
} | ||
digitalWrite(this->fwd_pin, HIGH); | ||
digitalWrite(this->rev_pin, LOW); | ||
} | ||
|
||
/** | ||
* @brief drive the motor in reverse | ||
*/ | ||
void ZXMB5210::rev(void){ | ||
if(this->buck_enable < 255){ // send power to the magnetorquers | ||
digitalWrite(this->buck_enable, HIGH); | ||
} | ||
digitalWrite(this->fwd_pin, LOW); | ||
digitalWrite(this->rev_pin, HIGH); | ||
|
||
} | ||
|
||
/** | ||
* @brief motor driver enters standby mode, with outputs to the motor floating | ||
*/ | ||
void ZXMB5210::standby(void){ | ||
if(this->buck_enable < 255){ // turn off power to the magnetorquers | ||
digitalWrite(this->buck_enable, LOW); | ||
} | ||
digitalWrite(this->fwd_pin, LOW); | ||
digitalWrite(this->rev_pin, LOW); | ||
|
||
} | ||
|
||
/** | ||
* @brief motor driver enters brake mode, with outputs to the motor both low, short circuit brake | ||
*/ | ||
void ZXMB5210::stop(void){ | ||
if(this->buck_enable < 255){ // turn off power to the magnetorquers | ||
digitalWrite(this->buck_enable, LOW); | ||
} | ||
digitalWrite(this->fwd_pin, HIGH); | ||
digitalWrite(this->rev_pin, HIGH); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef ZXMB5210_MAGNETORQUER_H | ||
#define ZXMB5210_MAGNETORQUER_H | ||
|
||
#include <Arduino.h> | ||
#include <global.h> | ||
|
||
class ZXMB5210 { | ||
private: | ||
uint8_t fwd_pin, rev_pin, buck_enable=255; | ||
|
||
public: | ||
ZXMB5210(uint8_t fwd, uint8_t rev, uint8_t buck); | ||
ZXMB5210(uint8_t fwd, uint8_t rev); | ||
|
||
void fwd(void); | ||
void rev(void); | ||
void standby(void); | ||
void stop(void); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters