Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
motor_sim.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_MOTOR_SIM_HPP_
25#define TAPROOT_MOTOR_SIM_HPP_
26
27#ifdef PLATFORM_HOSTED
28
29#include <cmath>
30#include <cstdint>
31
32namespace tap::motor::motorsim
33{
34class MotorSim
35{
36public:
37 struct Config
38 {
39 int16_t maxInputMag;
40 int16_t maxencoder;
41 float maxCurrent;
42 float currentLim;
43 float maxW;
44 float kt;
45 float wtGrad;
46 };
47
48 static constexpr Config M3508_CONFIG = {
49 .maxInputMag = 16'384,
50 .maxencoder = 8'192,
51 .maxCurrent = 20,
52 .currentLim = 10,
53 .maxW = 469,
54 .kt = 0.3f,
55 .wtGrad = 72,
56 };
57
58 MotorSim(const Config &config);
59
63 void reset();
64
70 void setMotorInput(int16_t in);
71
75 void setLoad(float load);
76
81 void update();
82
86 float getCurrent() const;
87
91 int16_t getEnc() const;
92
96 int16_t getInput() const;
97
101 float getMaxTorque() const;
102
106 int16_t getRPM() const;
107
108private:
109 const Config config;
110
111 /* Class Variables */
112 float load = 0; // N*m
113 int16_t enc = 0;
114 float rpm = 0;
115 int16_t input = 0;
116 uint32_t prevTime = 0;
117};
118} // namespace tap::motor::motorsim
119
120#endif // PLATFORM_HOSTED
121
122#endif // TAPROOT_MOTOR_SIM_HPP_
Config(double p, double i, double d, double maxIntegralAccumulation, double maxOutput, double errorDerivativeFloor, double errorDeadzone=0.0, double tQDerivativeKalman=1.0, double tRDerivativeKalman=0.0, tRProportionalKalman=1.0)
Definition dimensional_smooth_pid.hpp:16
Definition pwm_info.hpp:4