Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
governor_limited_command.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_GOVERNOR_LIMITED_COMMAND_HPP_
25#define TAPROOT_GOVERNOR_LIMITED_COMMAND_HPP_
26
27#include <array>
28#include <cassert>
29#include <vector>
30
31#include "../command.hpp"
32
34
36{
44template <size_t NUM_CONDITIONS>
46{
47public:
49 const std::vector<Subsystem *> &subRequirements,
50 Command &command,
51 const std::array<CommandGovernorInterface *, NUM_CONDITIONS> &commandGovernorList)
52 : command(command),
53 commandGovernorList(commandGovernorList)
54 {
55 std::for_each(subRequirements.begin(), subRequirements.end(), [&](auto sub) {
56 addSubsystemRequirement(sub);
57 });
58 assert(command.getRequirementsBitwise() == this->getRequirementsBitwise());
59 }
60
61 const char *getName() const override { return command.getName(); }
62
63 bool isReady() override
64 {
65 return std::all_of(
66 commandGovernorList.begin(),
67 commandGovernorList.end(),
68 [](auto governor) { return governor->isReady(); }) &&
69 command.isReady();
70 }
71
72 void initialize() override
73 {
74 command.initialize();
75
76 for (auto governor : commandGovernorList)
77 {
78 governor->onGovernedCommandInitialized();
79 }
80 }
81
82 void execute() override { command.execute(); }
83
84 void end(bool interrupted) override { command.end(interrupted); }
85
86 bool isFinished() const override
87 {
88 return std::any_of(
89 commandGovernorList.begin(),
90 commandGovernorList.end(),
91 [](auto governor) { return governor->isFinished(); }) ||
92 command.isFinished();
93 }
94
95private:
96 Command &command;
97
98 std::array<CommandGovernorInterface *, NUM_CONDITIONS> commandGovernorList;
99};
100} // namespace tap::control::governor
101
102#endif // TAPROOT_GOVERNOR_LIMITED_COMMAND_HPP_
Definition command.hpp:44
virtual void initialize()=0
virtual bool isFinished() const =0
virtual void execute()=0
virtual const char * getName() const =0
mockable subsystem_scheduler_bitmap_t getRequirementsBitwise() const
Definition command.hpp:64
virtual bool isReady()
Definition command.cpp:46
virtual void end(bool interrupted)=0
Definition governor_limited_command.hpp:46
GovernorLimitedCommand(const std::vector< Subsystem * > &subRequirements, Command &command, const std::array< CommandGovernorInterface *, NUM_CONDITIONS > &commandGovernorList)
Definition governor_limited_command.hpp:48
const char * getName() const override
Definition governor_limited_command.hpp:61
bool isReady() override
Definition governor_limited_command.hpp:63
void initialize() override
Definition governor_limited_command.hpp:72
bool isFinished() const override
Definition governor_limited_command.hpp:86
void end(bool interrupted) override
Definition governor_limited_command.hpp:84
void execute() override
Definition governor_limited_command.hpp:82
Definition command_governor_interface.hpp:28