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

AM ported #1

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@
*.exe
*.out
*.app

.idea/
38 changes: 38 additions & 0 deletions AttitudeManager/Inc/AM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* AM.hpp
*
* Attitude Manager Header
*
* Created on: Oct 12, 2022
* Author(s): Anthony (anni) Luo; Dhruv Upadhyay
*/
#ifndef ZPSW3_AM_HPP
#define ZPSW3_AM_HPP

#include "LOS_Link.hpp"
#include "LOS_Actuators.hpp"
#include "AM_StateManager.hpp"

class AttitudeState;

namespace AM {
// Gives status of attitude manager so we know when it has completed a cycle (its state is FetchInstructionsMode) or entered failure mode
enum _Attitude_Manager_Cycle_Status {COMPLETED_CYCLE = 0, IN_CYCLE, FAILURE_MODE};
}

class AttitudeManager {
public:
AttitudeManager(LOS_Link *link, LOS_Actuators *output);
inline AttitudeState* getCurrentState() const {return currentState;}
void execute();
void setState(AttitudeState& newState);
AM::_Attitude_Manager_Cycle_Status getStatus() {return status;}
LOS_Link *link;
LOS_Actuators *output;
private:
AttitudeState* currentState;
AM::_Attitude_Manager_Cycle_Status status;
AttitudeManager();
};

#endif //ZPSW3_AM_HPP
21 changes: 21 additions & 0 deletions AttitudeManager/Inc/AM_DataTypes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by Anthony Luo on 2022-10-13.
//

#ifndef ZPSW3_AM_DATATYPES_HPP
#define ZPSW3_AM_DATATYPES_HPP

typedef struct {
int some_data_here;
} Position_t;


enum flight_mode: int8_t {
fm_fatal_failure = -1,
fm_limp = 0,
fm_stabilize = 1,
fm_gps = 2,
fm_autonomous = 3
};

#endif //ZPSW3_AM_DATATYPES_HPP
24 changes: 24 additions & 0 deletions AttitudeManager/Inc/AM_Interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* AM_Interface.h
*
* Interface so that freeRTOS can call C-style functions while dev is in c++
*
* Created on: Oct 12, 2022
* Author(s): Anthony (anni) Luo; Dhruv Upadhyay
*/

#ifndef ZPSW3_AM_INTERFACE_H
#define ZPSW3_AM_INTERFACE_H

#ifdef __cplusplus
extern "C" {
#endif

void AM_InterfaceInit(void);
void AM_InterfaceExecute(void);

#ifdef __cplusplus
}
#endif

#endif //ZPSW3_AM_INTERFACE_H
27 changes: 27 additions & 0 deletions AttitudeManager/Inc/AM_StateManager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* AM_StateManager.hpp
*
* Attitude State-Machine header
*
* Created on: Oct 12, 2022
* Author(s): Anthony (anni) Luo; Dhruv Upadhyay
*/

#ifndef ZPSW3_AM_STATEMANAGER_HPP
#define ZPSW3_AM_STATEMANAGER_HPP

#include "AM.hpp"

class AttitudeManager;

class AttitudeState {
public:
virtual void enter(AttitudeManager* attitudeMgr) = 0;
virtual void execute(AttitudeManager* attitudeMgr) = 0;
virtual void exit(AttitudeManager* attitudeMgr) = 0;

bool operator==(const AttitudeState& rhs) const {return (this == &rhs);}

virtual ~AttitudeState() {}
};
#endif //ZPSW3_AM_STATEMANAGER_HPP
149 changes: 149 additions & 0 deletions AttitudeManager/Inc/AM_States.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* AM_States.hpp
*
* Attitude Manager State-Machine header file
*
* Describes the states of AM:
*
* Init / Disarm / FetchInstructionsMode (all in one rn)
* ControlLoopMode [ run our control loops ]
* OutputMixingMode [ where we mix outputs ] ? does this include telemetry
*
*/

#ifndef ZPSW3_AM_STATES_HPP
#define ZPSW3_AM_STATES_HPP

#include "AM_StateManager.hpp"
#include "AM_DataTypes.hpp"


/* not being used at the moment
* will be brought it after things start working incrementally
**/
class DisarmMode: public AttitudeState {
public:
void enter(AttitudeManager *att_man) {
(void) att_man;
}
void execute(AttitudeManager *att_man);
void exit(AttitudeManager *att_man) {
(void) att_man;
}
static AttitudeState& getInstance();
private:
DisarmMode() {
}
DisarmMode(const DisarmMode &other);
DisarmMode& operator =(const DisarmMode &other);
static bool receieveArmDisarmInstruction(AttitudeManager *att_man);
static bool isArmed();
static uint8_t m_arm_disarm_ppm_val;
static uint8_t m_arm_disarm_timeout_count;
};

class FetchInstructionsMode : public AttitudeState {
public:
void enter(AttitudeManager *att_man) {
(void) att_man;
}

void execute(AttitudeManager *att_man);

void exit(AttitudeManager *att_man) {
(void) att_man;
}

static AttitudeState &getInstance();

static flight_mode getFlightMode(void) {
return FetchInstructionsMode::m_flight_mode;
}

static Teleop_Instructions_t *getTeleopInstructions(void) {
return &m_teleop_instructions;
}

private:
FetchInstructionsMode() {
// TODO: to be implemented
}

FetchInstructionsMode(const FetchInstructionsMode &other);

FetchInstructionsMode &operator=(const FetchInstructionsMode &other);

static bool receiveTeleopInstructions(AttitudeManager *att_man);

static bool isArmed();

static Teleop_Instructions_t m_teleop_instructions;
static flight_mode m_flight_mode;
static uint8_t m_teleop_timeout_count;
static Position_t m_pos;
};

class ControlLoopMode : public AttitudeState {
public:
void enter(AttitudeManager *att_man) {
(void) att_man;
}
void execute(AttitudeManager *att_man);
void exit(AttitudeManager *att_man) {
(void) att_man;
}
static AttitudeState& getInstance();
static Controls_Output_t* getControlsOutput(void) {
return m_controls_output
}
private:
ControlLoopMode() {

}
ControlLoopMode(const ControlLoopMode &other);
ControlLoopMode& operator = (const ControlLoopMode &other);
static Controls_Output_t *m_controls_output
};

class OutputMixingMode : public AttitudeState {
public:
void enter(AttitudeManager *att_man) {
(void) att_man;
}
void execute(AttitudeManager *att_man) {
(void) att_man;
}
void exit(AttitudeManager *att_man) {
(void) att_man;
}
static AttitudeState& getInstance();
static float* getChannelOut(void) {
return m_channel_out;
}
private:
OutputMixingMode() {

}
OutputMixingMode(const OutputMixingMode &other);
OutputMixingMode& operator = (const OutputMixingMode &other);
static float m_channel_out[5]; //FIXME: make this a data struct
};

class FatalFailureMode: public AttitudeState {
public:
void enter(AttitudeManager *att_man) {
(void) att_man;
}
void execute(AttitudeManager *att_man);
void exit(AttitudeManager *att_man) {
(void) att_man;
}
static AttitudeState& getInstance();
private:
FatalFailureMode() {
}
FatalFailureMode(const FatalFailureMode &other);
FatalFailureMode& operator =(const FatalFailureMode &other);
};

#endif //ZPSW3_AM_STATES_HPP
3 changes: 3 additions & 0 deletions AttitudeManager/Src/AM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//
// Created by Anthony Luo on 2022-10-12.
//
5 changes: 5 additions & 0 deletions AttitudeManager/Src/AM_Interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Created by Anthony Luo on 2022-10-12.
//

#include "../Inc/AM_Interface.h"
Loading