Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
fuzzy_pd_rule_table.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2022 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_FUZZY_PD_RULE_TABLE_HPP_
25#define TAPROOT_FUZZY_PD_RULE_TABLE_HPP_
26
27#include <array>
28
29#include "fuzzy_rule_table.hpp"
30
31namespace tap::algorithms
32{
47{
48public:
60
65 FuzzyPDRuleTable() : kpArray{}, kdArray{} {}
66
77 const std::array<float, NUM_FUZZY_MEMBERS> &kpParams,
78 const std::array<float, NUM_FUZZY_MEMBERS> &kdParams)
79 : kpArray(kpParams),
80 kdArray(kdParams)
81 {
82 }
83
85 modm::Matrix<float, 2, 1> performFuzzyUpdate(float e, float d) override;
86
88 inline modm::Matrix<float, 2, 1> getFuzzyGains() const override { return fuzzyGains; }
89
90private:
99 void performFuzzification(float e, float d);
100
105 void updateFuzzyMatrix();
106
108 void performDefuzzification();
109
121 static inline void performSingleValueFuzzification(
122 const float value,
123 std::array<float, NUM_FUZZY_MEMBERS> &fuzzificationMemberValues)
124 {
125 if (value < 0)
126 {
127 // value < 0 means the positive triangle function is 0 and the negative and zero members
128 // should be updated
129
130 // The value should be mapped from [-1, 0] to [1, 0] (i.e. if -1, the negative member
131 // value should be 1)
132 fuzzificationMemberValues[N] = std::min(-value, 1.0f);
133 // The value should be mapped from [-1, 0] to [0, 1] (i.e. if the value is 0, the zero
134 // member value should be 1)
135 fuzzificationMemberValues[Z] = std::max(value + 1.0f, 0.0f);
136 fuzzificationMemberValues[P] = 0;
137 }
138 else
139 {
140 // value > 0 means negative triangle function is 0 and positive and zero members should
141 // be updated
142
143 fuzzificationMemberValues[N] = 0;
144 // The value should be mapped from [0, 1] to [1, 0] (i.e. if the value is 0, the zero
145 // member value should be 1)
146 fuzzificationMemberValues[Z] = std::max(1.0f - value, 0.0f);
147 // The value should be mapped from [0, 1] to [0, 1] (direct mapping)
148 fuzzificationMemberValues[P] = std::min(value, 1.0f);
149 }
150 }
151
152private:
153 std::array<float, NUM_FUZZY_MEMBERS> errorFuzzificationMemberValues = {};
154 std::array<float, NUM_FUZZY_MEMBERS> derivativeFuzzificationMemberValues = {};
155 std::array<std::array<float, NUM_FUZZY_MEMBERS>, NUM_FUZZY_MEMBERS> fuzzyMatrix = {};
156 modm::Matrix<float, 2, 1> fuzzyGains = {};
157 std::array<float, NUM_FUZZY_MEMBERS> kpArray;
158 std::array<float, NUM_FUZZY_MEMBERS> kdArray;
159};
160} // namespace tap::algorithms
161
162#endif // TAPROOT_FUZZY_PD_RULE_TABLE_HPP_
Definition fuzzy_pd_rule_table.hpp:47
modm::Matrix< float, 2, 1 > getFuzzyGains() const override
Definition fuzzy_pd_rule_table.hpp:88
FuzzyPDRuleTable()
Definition fuzzy_pd_rule_table.hpp:65
FuzzyMembers
Definition fuzzy_pd_rule_table.hpp:54
@ P
Positive error.
Definition fuzzy_pd_rule_table.hpp:57
@ NUM_FUZZY_MEMBERS
Definition fuzzy_pd_rule_table.hpp:58
@ N
Negative error.
Definition fuzzy_pd_rule_table.hpp:55
@ Z
Zero error.
Definition fuzzy_pd_rule_table.hpp:56
modm::Matrix< float, 2, 1 > performFuzzyUpdate(float e, float d) override
Definition fuzzy_pd_rule_table.cpp:124
FuzzyPDRuleTable(const std::array< float, NUM_FUZZY_MEMBERS > &kpParams, const std::array< float, NUM_FUZZY_MEMBERS > &kdParams)
Definition fuzzy_pd_rule_table.hpp:76
Definition fuzzy_rule_table.hpp:41
DUnit d
Definition dimensional_smooth_pid.hpp:3
Definition ballistics.cpp:29