Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit 572bd5e

Browse files
committed
trying to fix merge with failsafe
1 parent 0282fdf commit 572bd5e

File tree

872 files changed

+246780
-238916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

872 files changed

+246780
-238916
lines changed

.DS_Store

-8 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
# Executables
2020
*.exe *.out *.app
2121

22+
.DS_Store
23+
2224
.idea/
2325
.vscode/
24-
.DS_Store/
25-
Tools/*/build
26+
Tools/*/build/
2627
Debug/
2728
/.metadata/

.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<projectDescription>
3-
<name>ZeroPilot-SW-3.5</name>
3+
<name>efs-zeropilot-3.5</name>
44
<comment></comment>
55
<projects>
66
</projects>

AttitudeManager/FlightModes/Inc/AM_ControlAlgorithm.hpp

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef ZPSW3_AM_FBWA_HPP
2+
#define ZPSW3_AM_FBWA_HPP
3+
4+
#include "flightmode.hpp"
5+
6+
namespace AM {
7+
8+
class FBWA : public Flightmode {
9+
public:
10+
FBWA() = default;
11+
12+
AttitudeManagerInput run(const AttitudeManagerInput& input) override;
13+
void updatePid() override;
14+
void updatePidGains() override;
15+
void updateControlLimits(ControlLimits_t limits) override;
16+
17+
private:
18+
// TODO: FIXME to be a control limit class
19+
ControlLimits_t fbwa_control_limits;
20+
};
21+
22+
} // namespace AM
23+
24+
#endif // ZPSW3_AM_FBWA_HPP
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* AM_ControlAlgorithm.hpp
3+
*
4+
* Attitude Manager Control Algorithm Interface
5+
*
6+
* Created on: Oct 22, 2022
7+
* Author(s): Aidan Bowers
8+
*/
9+
#ifndef ZPSW3_AM_CONTROL_INTERFACE_HPP
10+
#define ZPSW3_AM_CONTROL_INTERFACE_HPP
11+
12+
#include "CommonDataTypes.hpp"
13+
14+
namespace AM {
15+
16+
class Flightmode {
17+
public:
18+
virtual ~Flightmode() = default;
19+
20+
virtual AttitudeManagerInput run(const AttitudeManagerInput& input) = 0;
21+
virtual void updatePid() = 0;
22+
virtual void updatePidGains() = 0;
23+
virtual void updateControlLimits(ControlLimits_t limits) = 0;
24+
25+
protected:
26+
Flightmode() = default;
27+
};
28+
29+
} // namespace AM
30+
31+
#endif // ZPSW3_AM_CONTROL_INTERFACE_HPP
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef ZPSW3_AM_MANUAL_HPP
2+
#define ZPSW3_AM_MANUAL_HPP
3+
4+
#include "flightmode.hpp"
5+
6+
namespace AM {
7+
8+
class Manual : public Flightmode {
9+
public:
10+
Manual() = default;
11+
12+
AttitudeManagerInput run(const AttitudeManagerInput& input) override;
13+
void updatePid() override;
14+
void updatePidGains() override;
15+
void updateControlLimits(ControlLimits_t limits) override;
16+
};
17+
18+
} // namespace AM
19+
20+
#endif // ZPSW3_AM_MANUAL_HPP
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "fbwa.hpp"
2+
#include "CommonDataTypes.hpp"
3+
#include "AM.hpp"
4+
#include <cassert>
5+
6+
namespace AM {
7+
AttitudeManagerInput FBWA::run(const AttitudeManagerInput& input) {
8+
9+
AttitudeManagerInput mappedOutputs;
10+
11+
// TODO: bound checking that doesn't throw an abort() and program exit
12+
// Bounded checking to make sure input is within max and min
13+
// assert(input.pitch <= AM::AttitudeManager::INPUT_MAX && input.pitch >= AM::AttitudeManager::INPUT_MIN);
14+
// assert(input.roll <= AM::AttitudeManager::INPUT_MAX && input.roll >= AM::AttitudeManager::INPUT_MIN);
15+
// assert(input.yaw <= AM::AttitudeManager::INPUT_MAX && input.yaw >= AM::AttitudeManager::INPUT_MIN);
16+
// assert(input.throttle <= AM::AttitudeManager::INPUT_MAX && input.throttle >= AM::AttitudeManager::INPUT_MIN);
17+
18+
// Mapping inputs to outputs with ratios of min-max
19+
// Mapping maintains 0->0 I/O
20+
mappedOutputs.pitch =
21+
input.pitch < 0
22+
? input.pitch * (fbwa_control_limits.pitchLimit.min / AM::AttitudeManager::INPUT_MIN)
23+
: input.pitch * (fbwa_control_limits.pitchLimit.max / AM::AttitudeManager::INPUT_MAX);
24+
mappedOutputs.roll =
25+
input.roll < 0
26+
? input.roll * (fbwa_control_limits.rollLimit.min / AM::AttitudeManager::INPUT_MIN)
27+
: input.roll * (fbwa_control_limits.rollLimit.max / AM::AttitudeManager::INPUT_MAX);
28+
mappedOutputs.yaw =
29+
input.yaw < 0
30+
? input.yaw * (fbwa_control_limits.yawLimit.min / AM::AttitudeManager::INPUT_MIN)
31+
: input.yaw * (fbwa_control_limits.yawLimit.max / AM::AttitudeManager::INPUT_MAX);
32+
33+
// Throttle maps -100-100 to range 0-100
34+
mappedOutputs.throttle =
35+
fbwa_control_limits.throttleLimit.min +
36+
(input.throttle - AM::AttitudeManager::INPUT_MIN) *
37+
(fbwa_control_limits.throttleLimit.max - fbwa_control_limits.throttleLimit.min) /
38+
(AM::AttitudeManager::INPUT_MAX - AM::AttitudeManager::INPUT_MIN);
39+
40+
return mappedOutputs;
41+
}
42+
43+
void FBWA::updatePid() {} //Needs to be implemented
44+
45+
void FBWA::updatePidGains() {} //Needs to be implemented
46+
47+
void FBWA::updateControlLimits(ControlLimits_t limits) {
48+
// TODO: make this better than a straight copy
49+
fbwa_control_limits = limits;
50+
}
51+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "manual.hpp"
2+
#include "CommonDataTypes.hpp"
3+
4+
namespace AM {
5+
6+
AttitudeManagerInput Manual::run(const AttitudeManagerInput& input) {
7+
return input;
8+
}
9+
10+
void Manual::updatePid() {}
11+
void Manual::updatePidGains() {}
12+
void Manual::updateControlLimits(ControlLimits_t limits) {}
13+
14+
} // namespace AM

AttitudeManager/Inc/AM.hpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,59 @@
99
#ifndef ZPSW3_AM_HPP
1010
#define ZPSW3_AM_HPP
1111

12-
#include "AM_ControlAlgorithm.hpp"
1312
#include "CommonDataTypes.hpp"
14-
13+
#include "config_foundation.hpp"
1514
#include "FreeRTOS.h"
15+
#include "flightmode.hpp"
1616
#include "semphr.h"
17+
#ifdef TESTING
18+
#include <gtest/gtest_prod.h>
19+
#endif
1720

1821
namespace AM {
1922

23+
typedef struct {
24+
MotorChannel *motorInstance;
25+
bool isInverted;
26+
} MotorInstance_t;
27+
2028
class AttitudeManager {
2129
public:
30+
31+
//Constants used for mapping values
32+
static constexpr float INPUT_MAX = 100;
33+
static constexpr float INPUT_MIN = -100;
34+
2235
static void setControlInputs(const AttitudeManagerInput& new_control_inputs);
2336

2437
static AttitudeManagerInput getControlInputs();
2538

26-
AttitudeManager(Flightmode* control_algorithm) : control_algorithm(control_algorithm){};
39+
AttitudeManager(Flightmode* controlAlgorithm, MotorInstance_t *(&motorInstances)[], uint8_t (&numMotorsPerAxis)[]);
2740

28-
void runControlLoopIteration(const AttitudeManagerInput& instructions);
41+
~AttitudeManager();
42+
43+
void runControlLoopIteration();
2944

3045
private:
46+
#ifdef TESTING
47+
FRIEND_TEST(AttitudeManager, MotorInitializationAndOutput); // Remove FRIEND_TEST when updating tests with setControlInputs
48+
FRIEND_TEST(AttitudeManagerOutputToMotor, NoMotors);
49+
FRIEND_TEST(AttitudeManagerOutputToMotor, MotorsOfSameAxis);
50+
FRIEND_TEST(AttitudeManagerOutputToMotor, setOutputInRandomAxisOrder);
51+
FRIEND_TEST(AttitudeManagerOutputToMotor, InvertedTest);
52+
FRIEND_TEST(AttitudeManagerOutputToMotor, CombinedTest);
53+
#endif
54+
3155
AttitudeManager();
56+
void outputToMotor(ControlAxis_t axis, uint8_t percent);
3257

3358
static SemaphoreHandle_t control_inputs_mutex;
34-
3559
static struct AttitudeManagerInput control_inputs;
3660

37-
Flightmode* control_algorithm;
61+
Flightmode *controlAlgorithm_;
62+
MotorInstance_t *(&motorInstances_)[];
63+
uint8_t (&numMotorsPerAxis_)[];
64+
3865
};
3966

4067
} // namespace AM

0 commit comments

Comments
 (0)