Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
command_scheduler.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2021 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_COMMAND_SCHEDULER_HPP_
25#define TAPROOT_COMMAND_SCHEDULER_HPP_
26
27#include <iterator>
28
29#include "tap/util_macros.hpp"
30
32
33namespace tap
34{
35class Drivers;
36namespace control
37{
38class Command;
39class Subsystem;
40
52{
53public:
55 virtual bool operator()() { return false; }
56};
57
118{
119public:
121 Drivers* drivers,
122 bool masterScheduler = false,
123 SafeDisconnectFunction* safeDisconnectFunction =
124 &CommandScheduler::defaultSafeDisconnectFunction);
127
148 mockable void run();
149
172 mockable void addCommand(Command* commandToAdd);
173
184 mockable void removeCommand(Command* command, bool interrupted);
185
190 mockable bool isCommandScheduled(const Command* command) const;
191
200 mockable void registerSubsystem(Subsystem* subsystem);
201
209
214 mockable bool isSubsystemRegistered(const Subsystem* subsystem) const;
215
220
226 mockable void runHardwareTest(const Subsystem* subsystem);
227
232
238 mockable void stopHardwareTest(const Subsystem* subsystem);
239
244
249 mockable bool isRunningTest(const Subsystem* subsystem);
250
255 mockable bool hasPassedTest(const Subsystem* subsystem);
256
260 mockable int subsystemListSize() const;
261
265 mockable int commandListSize() const;
266
271 {
272 using iterator_category = std::forward_iterator_tag;
273 using difference_type = std::ptrdiff_t;
275 using pointer = Command*;
277
278 CommandIterator(CommandScheduler* scheduler, int i);
279
281
282 // Prefix increment
284
285 // Postfix increment
287
288 friend bool operator==(const CommandIterator& a, const CommandIterator& b);
289 friend bool operator!=(const CommandIterator& a, const CommandIterator& b);
290
291 private:
292 CommandScheduler* scheduler;
293 int currIndex;
294 };
295
300 {
301 using iterator_category = std::forward_iterator_tag;
302 using difference_type = std::ptrdiff_t;
306
307 SubsystemIterator(CommandScheduler* scheduler, int i);
308
310
311 // Prefix increment
313
314 // Postfix increment
316
317 friend bool operator==(const SubsystemIterator& a, const SubsystemIterator& b);
318 friend bool operator!=(const SubsystemIterator& a, const SubsystemIterator& b);
319
320 private:
321 CommandScheduler* scheduler;
322 int currIndex;
323 };
324
329
331 {
332 return registeredSubsystemBitmap;
333 }
334 mockable command_scheduler_bitmap_t getAddedCommandBitmap() const { return addedCommandBitmap; }
335
336 static int constructCommand(Command* command);
337 static int constructSubsystem(Subsystem* subsystem);
338 static void destructCommand(Command* command);
339 static void destructSubsystem(Subsystem* subsystem);
340
341private:
343 static constexpr float MAX_ALLOWABLE_SCHEDULER_RUNTIME = 100;
344 static constexpr int MAX_SUBSYSTEM_COUNT = sizeof(subsystem_scheduler_bitmap_t) * 8;
345 static constexpr int MAX_COMMAND_COUNT = sizeof(command_scheduler_bitmap_t) * 8;
346 static constexpr subsystem_scheduler_bitmap_t LSB_ONE_HOT_SUBSYSTEM_BITMAP = 1;
347 static constexpr command_scheduler_bitmap_t LSB_ONE_HOT_COMMAND_BITMAP = 1;
348 static constexpr int INVALID_ITER_INDEX = -1;
349
357 static int maxSubsystemIndex;
358
363 static Subsystem* globalSubsystemRegistrar[MAX_SUBSYSTEM_COUNT];
364
369 static int maxCommandIndex;
370
375 static Command* globalCommandRegistrar[MAX_COMMAND_COUNT];
376
380 static bool masterSchedulerExists;
381
386 bool safeDisconnected();
387
389
393 static SafeDisconnectFunction defaultSafeDisconnectFunction;
394
399 SafeDisconnectFunction* safeDisconnectFunction;
400
406 subsystem_scheduler_bitmap_t registeredSubsystemBitmap = 0;
407
413 subsystem_scheduler_bitmap_t subsystemsAssociatedWithCommandBitmap = 0;
414
420 subsystem_scheduler_bitmap_t subsystemsPassingHardwareTests = 0;
421
426 command_scheduler_bitmap_t addedCommandBitmap = 0;
427
428 bool isMasterScheduler = false;
429}; // class CommandScheduler
430
431} // namespace control
432
433} // namespace tap
434
435#endif // TAPROOT_COMMAND_SCHEDULER_HPP_
Definition drivers.hpp:70
Definition command_scheduler.hpp:118
mockable SubsystemIterator subMapEnd()
Definition command_scheduler.cpp:466
mockable int countRunningHardwareTests()
Definition command_scheduler.cpp:400
mockable void runHardwareTest(const Subsystem *subsystem)
Definition command_scheduler.cpp:366
static void destructSubsystem(Subsystem *subsystem)
Definition command_scheduler.cpp:119
mockable void addCommand(Command *commandToAdd)
Definition command_scheduler.cpp:252
mockable CommandIterator cmdMapEnd()
Definition command_scheduler.cpp:456
mockable void runAllHardwareTests()
Definition command_scheduler.cpp:358
static int constructCommand(Command *command)
Definition command_scheduler.cpp:48
static int constructSubsystem(Subsystem *subsystem)
Definition command_scheduler.cpp:73
mockable void removeCommand(Command *command, bool interrupted)
Definition command_scheduler.cpp:305
mockable int commandListSize() const
Definition command_scheduler.cpp:438
mockable CommandIterator cmdMapBegin()
Definition command_scheduler.cpp:451
mockable bool isRunningTest(const Subsystem *subsystem)
Definition command_scheduler.cpp:414
mockable bool hasPassedTest(const Subsystem *subsystem)
Definition command_scheduler.cpp:419
mockable ~CommandScheduler()
Definition command_scheduler.cpp:160
mockable void registerSubsystem(Subsystem *subsystem)
Definition command_scheduler.cpp:333
mockable command_scheduler_bitmap_t getAddedCommandBitmap() const
Definition command_scheduler.hpp:334
mockable void stopHardwareTest(const Subsystem *subsystem)
Definition command_scheduler.cpp:391
mockable void stopAllHardwareTests()
Definition command_scheduler.cpp:377
mockable SubsystemIterator subMapBegin()
Definition command_scheduler.cpp:461
mockable subsystem_scheduler_bitmap_t getRegisteredSubsystemBitmap() const
Definition command_scheduler.hpp:330
mockable void setSafeDisconnectFunction(SafeDisconnectFunction *func)
Set the SafeDisconnectFunction to the given function.
Definition command_scheduler.cpp:326
mockable void run()
Definition command_scheduler.cpp:168
mockable bool isSubsystemRegistered(const Subsystem *subsystem) const
Definition command_scheduler.cpp:351
mockable int subsystemListSize() const
Definition command_scheduler.cpp:425
mockable bool isCommandScheduled(const Command *command) const
Definition command_scheduler.cpp:299
static void destructCommand(Command *command)
Definition command_scheduler.cpp:101
Definition command.hpp:44
Definition command_scheduler.hpp:52
virtual bool operator()()
Definition command_scheduler.hpp:55
SafeDisconnectFunction()
Definition command_scheduler.hpp:54
Definition subsystem.hpp:54
IUnit i
Definition dimensional_smooth_pid.hpp:2
uint64_t command_scheduler_bitmap_t
Definition command_scheduler_types.hpp:31
uint64_t subsystem_scheduler_bitmap_t
Definition command_scheduler_types.hpp:32
Definition ballistics.cpp:29
tap::Drivers Drivers
Definition drivers.hpp:11
fang::Drivers & drivers
Definition robot_singleton.cpp:45
Definition command_scheduler.hpp:271
std::ptrdiff_t difference_type
Definition command_scheduler.hpp:273
friend bool operator==(const CommandIterator &a, const CommandIterator &b)
Definition command_scheduler.cpp:527
CommandIterator & operator++()
Definition command_scheduler.cpp:497
pointer operator*()
Definition command_scheduler.cpp:492
std::forward_iterator_tag iterator_category
Definition command_scheduler.hpp:272
friend bool operator!=(const CommandIterator &a, const CommandIterator &b)
Definition command_scheduler.cpp:534
Definition command_scheduler.hpp:300
SubsystemIterator & operator++()
Definition command_scheduler.cpp:567
friend bool operator!=(const SubsystemIterator &a, const SubsystemIterator &b)
Definition command_scheduler.cpp:604
pointer operator*()
Definition command_scheduler.cpp:562
friend bool operator==(const SubsystemIterator &a, const SubsystemIterator &b)
Definition command_scheduler.cpp:597
std::forward_iterator_tag iterator_category
Definition command_scheduler.hpp:301
std::ptrdiff_t difference_type
Definition command_scheduler.hpp:302
#define mockable
Wrap class functions that are not already virtual in this function if you wish to mock them.
Definition util_macros.hpp:38
#define DISALLOW_COPY_AND_ASSIGN(Typename)
Definition util_macros.hpp:27