Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
sequential_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) 2024-2025 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_SEQUENTIAL_COMMAND_HPP_
25#define TAPROOT_SEQUENTIAL_COMMAND_HPP_
26
27#include <array>
28
29#include "modm/architecture/interface/assert.hpp"
30
31#include "command.hpp"
33
34namespace tap
35{
36namespace control
37{
44template <size_t COMMANDS>
46{
47public:
48 SequentialCommand(std::array<Command*, COMMANDS> commands)
49 : Command(),
50 commands(commands),
51 currentCommand(0)
52 {
53 for (Command* command : commands)
54 {
55 modm_assert(
56 command != nullptr,
57 "SequentialCommand::SequentialCommand",
58 "Null pointer command passed into sequential command.");
59 this->commandRequirementsBitwise |= (command->getRequirementsBitwise());
60 }
61 }
62
63 const char* getName() const override
64 {
65 return this->currentCommand == COMMANDS ? ""
66 : this->commands[this->currentCommand]->getName();
67 }
68
69 bool isReady() override { return this->commands[0]->isReady(); }
70
71 void initialize() override
72 {
73 this->currentCommand = 0;
74 this->commandInitialized = false;
75 }
76
77 void execute() override
78 {
79 if (!this->commandInitialized)
80 {
81 if (this->commands[this->currentCommand]->isReady())
82 {
83 this->commands[this->currentCommand]->initialize();
84 this->commandInitialized = true;
85 }
86 }
87
88 if (this->commandInitialized)
89 {
90 this->commands[this->currentCommand]->execute();
91
92 if (this->commands[this->currentCommand]->isFinished())
93 {
94 this->commands[this->currentCommand]->end(false);
95 this->commandInitialized = false;
96 this->currentCommand++;
97 }
98 }
99 }
100
101 void end(bool interrupted) override
102 {
103 if (this->currentCommand != COMMANDS)
104 {
105 this->commands[this->currentCommand]->end(interrupted);
106 }
107 }
108
109 bool isFinished() const override { return this->currentCommand == COMMANDS; }
110
111private:
112 std::array<Command*, COMMANDS> commands;
113 size_t currentCommand;
114 bool commandInitialized;
115}; // class SequentialCommand
116
117} // namespace control
118
119} // namespace tap
120
121#endif // TAPROOT_SEQUENTIAL_COMMAND_HPP_
Definition command.hpp:44
command_scheduler_bitmap_t commandRequirementsBitwise
Definition command.hpp:139
Definition sequential_command.hpp:46
const char * getName() const override
Definition sequential_command.hpp:63
bool isFinished() const override
Definition sequential_command.hpp:109
void initialize() override
Definition sequential_command.hpp:71
void execute() override
Definition sequential_command.hpp:77
bool isReady() override
Definition sequential_command.hpp:69
SequentialCommand(std::array< Command *, COMMANDS > commands)
Definition sequential_command.hpp:48
void end(bool interrupted) override
Definition sequential_command.hpp:101
Definition ballistics.cpp:29