ClearCore Library
Loading...
Searching...
No Matches
EncoderInput.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Teknic, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
31#ifndef __ENCODER_INPUT_H__
32#define __ENCODER_INPUT_H__
33
34#include "PeripheralRoute.h"
35
37#define VEL_EST_SAMPLES 50
38
39namespace ClearCore {
40
41typedef void (*voidFuncPtr)(void);
42
55 friend class SysManager;
56public:
57
58#ifndef HIDE_FROM_DOXYGEN
59
64
76 volatile const int16_t& HwPosition() {
77 return m_hwPosn;
78 }
79
85 void IndexDetected(int16_t posn) {
86 m_hwIndex = posn;
87 m_processIndex = true;
88 }
89#endif
90
102 int32_t Position();
103
114 int32_t Position(int32_t newPosn);
115
124 void AddToPosition(int32_t posnAdjust);
125
141 int32_t IndexPosition();
142
151 void Enable(bool isEnabled);
152
161 void SwapDirection(bool isSwapped);
162
173 volatile const int32_t& Velocity() {
174 return m_velocity;
175 }
176
188 volatile const bool& IndexDetected() {
189 return m_indexDetected;
190 }
191
203 void IndexInverted(bool invert);
204
217
229
241 volatile const int16_t& StepsLastSample() {
242 return m_stepsLast;
243 }
244
245private:
246 const PeripheralRoute *m_aInfo;
247 const PeripheralRoute *m_bInfo;
248 const PeripheralRoute *m_indexInfo;
249 int32_t m_curPosn;
250 int32_t m_offsetAdjustment;
251 int32_t m_velocity;
252 int16_t m_hwPosn;
253 int32_t m_posnHistory[VEL_EST_SAMPLES];
254 uint8_t m_posnHistoryIndex;
255 bool m_enabled;
256 bool m_processIndex;
257 int16_t m_hwIndex;
258 int32_t m_indexPosn;
259 bool m_indexDetected;
260 bool m_indexInverted;
261 int16_t m_stepsLast;
262
263 void Initialize();
264
265 void Update();
266
267}; // EncoderInput
268
269} // ClearCore namespace
270
271#endif /* __ENCODER_INPUT_H__ */
#define VEL_EST_SAMPLES
Number of encoder samples to use for velocity calculation.
Definition EncoderInput.h:37
Defines the Peripheral Route structure, used in HardwareMapping.
ClearCore Position Sensor Decoder.
Definition EncoderInput.h:54
int32_t IndexPosition()
Read the last index position of the encoder.
void SwapDirection(bool isSwapped)
Swap the sense of positive and negative encoder directions.
volatile const bool & IndexDetected()
Check if there was an index pulse in the last sample time.
Definition EncoderInput.h:188
void Enable(bool isEnabled)
Set whether the encoder input should be active or not.
volatile const int16_t & StepsLastSample()
Get the number of encoder steps received in the last sample time.
Definition EncoderInput.h:241
int32_t Position()
Read the current position of the encoder.
bool QuadratureError()
Query for a quadrature error.
int32_t Position(int32_t newPosn)
Set the current position of the encoder.
volatile const int32_t & Velocity()
Read the velocity of the encoder input (counts per second)
Definition EncoderInput.h:173
void IndexInverted(bool invert)
Invert the edge that the index detection triggers on.
void AddToPosition(int32_t posnAdjust)
Adjust the current position of the encoder.
void ClearQuadratureError()
Clear a quadrature error.
ClearCore Board Supervisory System Manager.
Definition SysManager.h:58
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36
void(* voidFuncPtr)(void)
Definition DigitalIn.h:43