Skip to content

Commit

Permalink
Added ZXMB5210 Magnetorquer control lib!
Browse files Browse the repository at this point in the history
  • Loading branch information
grwells committed Apr 8, 2022
1 parent fcf951a commit 51dba0b
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#define DEBUG 1 /* if non-zero then debug statements will be printed over USB serial */


enum MotorDirection {REV=0, FWD=1};


/*
* Print a summary of the defines above and what their current ON/OFF state is.
*/
Expand Down
10 changes: 5 additions & 5 deletions include/samd51_pin_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
#define SUNSENSOR_A 13

// MAGNETORQUER CONTROL PINS
#define MAGNETORQUER_2_REV_PIN 4
#define MAGNETORQUER_2_FWD_PIN 22
#define MAGNETORQUER_2_REV_PIN 4 // reverse pin for ZXBM5210 controlling first magnetorquer
#define MAGNETORQUER_2_FWD_PIN 22 // same but forward pin

#define MAGNETORQUER_1_REV_PIN 23
#define MAGNETORQUER_1_FWD_PIN 24
#define MAGNETORQUER_1_REV_PIN 23 // reverse pin for ZXBM5210 controlling second magnetorquer
#define MAGNETORQUER_1_FWD_PIN 24 // same but forward pin

// BUCK CONVERTER
#define BUCK_ENABLE_PIN A5
#define BUCK_ENABLE_PIN A5 // Buck converter is ON when high, provides power to both magnetorquers

// UART
#define RX 0
Expand Down
2 changes: 1 addition & 1 deletion lib/DRV10970/src/DRV_10970.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define DRV_10970_H

#include <Arduino.h>
#include <global.h>
#include <samd51_pin_definitions.h>

// default pinout for the SAMD51
Expand All @@ -20,7 +21,6 @@ const int DRV_FG = FLYWHL_RPM_PIN, // frequency/rpm indication pin
DRV_PWM = FLYWHL_PWM_PIN, // pwm output pin
DRV_RD = FLYWHL_LOCK_INDICATION_PIN; // lock indication pin

enum MotorDirection {REV=0, FWD=1};

class DRV10970 {
private:
Expand Down
89 changes: 89 additions & 0 deletions lib/ZXMB5210/src/ZXMB5210.cpp
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);

}
22 changes: 22 additions & 0 deletions lib/ZXMB5210/src/ZXMB5210.h
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
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "supportFunctions.h"
#include "commandFunctions.h"
#include "DRV_10970.h"
#include "ZXMB5210.h"
#include "validation_tests.h" // tests for functionality

// Arduino library headers
Expand Down

0 comments on commit 51dba0b

Please sign in to comment.