REVLib - C++
SparkBaseConfig.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024-2026 REV Robotics
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of REV Robotics nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#pragma once
30
31#include <string>
32
33#include "rev/SparkBase.h"
43
44namespace rev::spark {
45
47public:
48 enum IdleMode : uint32_t { kCoast = 0, kBrake = 1 };
49
50 SparkBaseConfig() = default;
51 ~SparkBaseConfig() override = default;
52
55 SparkBaseConfig(SparkBaseConfig&&) noexcept = delete;
56 SparkBaseConfig& operator=(SparkBaseConfig&&) noexcept = delete;
57
58 struct Presets final {
61 static SparkBaseConfig config{
62 SparkBaseConfig().SmartCurrentLimit(60)};
63 return config;
64 }
65
68 static SparkBaseConfig config{
69 SparkBaseConfig().SmartCurrentLimit(60)};
70 return config;
71 }
72
75 static SparkBaseConfig config{
76 SparkBaseConfig().SmartCurrentLimit(15)};
77 return config;
78 }
79
82 static SparkBaseConfig config{
83 SparkBaseConfig().SmartCurrentLimit(80)};
84 return config;
85 }
86
87 /* CTRE - Minion: Standalone Brushless Motor */
89 static SparkBaseConfig config{
90 SparkBaseConfig().SmartCurrentLimit(30).AdvanceCommutation(
91 120.0)};
92 return config;
93 }
94 };
95
106 virtual SparkBaseConfig& Apply(SparkBaseConfig& config);
107
119
130 virtual SparkBaseConfig& Apply(AnalogSensorConfig& config);
131
142 virtual SparkBaseConfig& Apply(EncoderConfig& config);
143
154 virtual SparkBaseConfig& Apply(LimitSwitchConfig& config);
155
166 virtual SparkBaseConfig& Apply(SoftLimitConfig& config);
167
178 virtual SparkBaseConfig& Apply(ClosedLoopConfig& config);
179
190 virtual SparkBaseConfig& Apply(SignalsConfig& config);
191
199
209 SparkBaseConfig& Inverted(bool inverted);
210
236 SparkBaseConfig& SmartCurrentLimit(int stallLimit, int freeLimit = 0,
237 int limitRpm = 20000);
238
265 SparkBaseConfig& SecondaryCurrentLimit(double limit, int chopCycles = 0);
266
279 SparkBaseConfig& AdvanceCommutation(double byDegrees = 0.0);
280
290 SparkBaseConfig& OpenLoopRampRate(double rate);
291
302
310 SparkBaseConfig& VoltageCompensation(double nominalVoltage);
311
318
332 SparkBaseConfig& Follow(int leaderCanId, bool invert = false);
333
347 SparkBaseConfig& Follow(const SparkBase& leader, bool invert = false);
348
355
356 std::string Flatten() override;
357
365}; // class SparkBaseConfig
366
367} // namespace rev::spark
Definition: BaseConfig.h:40
Definition: AbsoluteEncoderConfig.h:35
Definition: AnalogSensorConfig.h:35
Definition: ClosedLoopConfig.h:44
Definition: EncoderConfig.h:35
Definition: LimitSwitchConfig.h:36
Definition: SignalsConfig.h:35
Definition: SoftLimitConfig.h:35
Definition: SparkBaseConfig.h:46
SparkBaseConfig & VoltageCompensation(double nominalVoltage)
Definition: SparkBaseConfig.cpp:138
EncoderConfig encoder
Definition: SparkBaseConfig.h:361
SparkBaseConfig & DisableVoltageCompensation()
Definition: SparkBaseConfig.cpp:145
~SparkBaseConfig() override=default
IdleMode
Definition: SparkBaseConfig.h:48
@ kCoast
Definition: SparkBaseConfig.h:48
@ kBrake
Definition: SparkBaseConfig.h:48
SoftLimitConfig softLimit
Definition: SparkBaseConfig.h:364
SparkBaseConfig & OpenLoopRampRate(double rate)
Definition: SparkBaseConfig.cpp:120
SparkBaseConfig & Inverted(bool inverted)
Definition: SparkBaseConfig.cpp:89
SparkBaseConfig(const SparkBaseConfig &)=default
virtual SparkBaseConfig & Apply(SparkBaseConfig &config)
Definition: SparkBaseConfig.cpp:37
SparkBaseConfig(SparkBaseConfig &&) noexcept=delete
ClosedLoopConfig closedLoop
Definition: SparkBaseConfig.h:360
SparkBaseConfig & DisableFollowerMode()
Definition: SparkBaseConfig.cpp:161
std::string Flatten() override
Definition: SparkBaseConfig.cpp:167
SparkBaseConfig & operator=(const SparkBaseConfig &)=delete
SignalsConfig signals
Definition: SparkBaseConfig.h:363
SparkBaseConfig & Follow(int leaderCanId, bool invert=false)
Definition: SparkBaseConfig.cpp:150
SparkBaseConfig & ClosedLoopRampRate(double rate)
Definition: SparkBaseConfig.cpp:129
AbsoluteEncoderConfig absoluteEncoder
Definition: SparkBaseConfig.h:358
AnalogSensorConfig analogSensor
Definition: SparkBaseConfig.h:359
SparkBaseConfig & AdvanceCommutation(double byDegrees=0.0)
Definition: SparkBaseConfig.cpp:114
SparkBaseConfig & SmartCurrentLimit(int stallLimit, int freeLimit=0, int limitRpm=20000)
Definition: SparkBaseConfig.cpp:94
LimitSwitchConfig limitSwitch
Definition: SparkBaseConfig.h:362
SparkBaseConfig & SecondaryCurrentLimit(double limit, int chopCycles=0)
Definition: SparkBaseConfig.cpp:106
SparkBaseConfig & SetIdleMode(IdleMode idleMode)
Definition: SparkBaseConfig.cpp:84
Definition: SparkBase.h:61
Definition: SparkLowLevel.cpp:40
Definition: SparkBaseConfig.h:58
static SparkBaseConfig & REV_NEO()
Definition: SparkBaseConfig.h:60
static SparkBaseConfig & REV_NEO_2()
Definition: SparkBaseConfig.h:67
static SparkBaseConfig & CTRE_Minion()
Definition: SparkBaseConfig.h:88
static SparkBaseConfig & REV_Vortex()
Definition: SparkBaseConfig.h:81
static SparkBaseConfig & REV_NEO_550()
Definition: SparkBaseConfig.h:74