CTRE_Phoenix 5.20.2
BasePigeon.h
1/*
2 * Software License Agreement
3 *
4 * Copyright (C) Cross The Road Electronics. All rights
5 * reserved.
6 *
7 * Cross The Road Electronics (CTRE) licenses to you the right to
8 * use, publish, and distribute copies of CRF (Cross The Road) firmware files (*.crf) and Software
9 * API Libraries ONLY when in use with Cross The Road Electronics hardware products.
10 *
11 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
12 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
14 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
16 * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
17 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
18 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
19 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
20 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
21 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE
22 */
23
24#pragma once
25
26#include <string>
27#include "ctre/phoenix/CANBusAddressable.h"
28#include "ctre/phoenix/CustomParamConfiguration.h"
29#include "ctre/phoenix/paramEnum.h"
30#include "ctre/phoenix/ErrorCode.h"
31#include "ctre/phoenix/sensors/PigeonIMU_ControlFrame.h"
32#include "ctre/phoenix/sensors/PigeonIMU_Faults.h"
33#include "ctre/phoenix/sensors/PigeonIMU_StatusFrame.h"
34#include "ctre/phoenix/sensors/PigeonIMU_StickyFaults.h"
35#include "ctre/phoenix/sensors/BasePigeonSimCollection.h"
36
37/* forward prototype */
38namespace ctre {
39namespace phoenix {
40namespace motorcontrol {
41namespace can {
42class TalonSRX;
43}
44}
45}
46}
47
48namespace ctre {
49namespace phoenix {
51namespace sensors {
52
58
62 std::string toString() {
63 return toString("");
64 }
65
71 std::string toString(std::string prependString) {
72 std::string retstr = CustomParamConfiguration::toString(prependString);
73
74 return retstr;
75 }
76};// struct BasePigeon
77
82private:
83 static BasePigeonConfiguration _default;
84public:
91 static bool CustomParam0Different (const BasePigeonConfiguration & settings) { return (!(settings.customParam0 == _default.customParam0)) || !settings.enableOptimizations; }
92 static bool CustomParam1Different (const BasePigeonConfiguration & settings) { return (!(settings.customParam1 == _default.customParam1)) || !settings.enableOptimizations; }
94};
95
101public:
102
111 BasePigeon(int deviceNumber, std::string const &version, std::string const &canbus = "");
112
113 ~BasePigeon();
114
119
130 int SetYaw(double angleDeg, int timeoutMs = 0);
141 int AddYaw(double angleDeg, int timeoutMs = 0);
151 int SetYawToCompass(int timeoutMs = 0);
152
163 int SetAccumZAngle(double angleDeg, int timeoutMs = 0);
180 ErrorCode Get6dQuaternion(double wxyz[4]) const;
190 ErrorCode GetYawPitchRoll(double ypr[3]) const;
195 double GetYaw() const;
200 double GetPitch() const;
205 double GetRoll() const;
213 int GetAccumGyro(double xyz_deg[3]) const;
224 double GetCompassHeading() const;
235 double GetTemp() const;
242 uint32_t GetUpTime() const;
250 int GetRawMagnetometer(int16_t rm_xyz[3]) const;
251
259 int GetBiasedMagnetometer(int16_t bm_xyz[3]) const;
267 int GetBiasedAccelerometer(int16_t ba_xyz[3]) const;
274 int GetRawGyro(double xyz_dps[3]) const;
278 uint32_t GetResetCount() const;
282 uint32_t GetResetFlags() const;
286 uint32_t GetFirmVers() const;
287
291 bool HasResetOccurred() const;
292
310 ErrorCode ConfigSetCustomParam(int newValue, int paramIndex, int timeoutMs = 0);
326 int ConfigGetCustomParam(int paramIndex, int timeoutMs = 0);
349 uint8_t subValue, int ordinal, int timeoutMs = 0);
367 double ConfigGetParameter(ctre::phoenix::ParamEnum param, int ordinal, int timeoutMs = 0);
387 ErrorCode ConfigGetParameter(ParamEnum param, int32_t valueToSend,
388 int32_t & valueReceived, uint8_t & subValue, int32_t ordinal,
389 int32_t timeoutMs);
390
405 int timeoutMs = 0);
406
419 int timeoutMs = 0) ;
430 int periodMs);
443 ErrorCode ClearStickyFaults(int timeoutMs = 0);
444
448 void* GetLowLevelHandle() const {
449 return _handle;
450 }
451
452 //------ All Configs ----------//
464 virtual ctre::phoenix::ErrorCode ConfigAllSettings(const BasePigeonConfiguration &allConfigs, int timeoutMs = 50);
474 virtual void GetAllConfigs(BasePigeonConfiguration &allConfigs, int timeoutMs = 50);
485 virtual ErrorCode ConfigFactoryDefault(int timeoutMs = 50);
486
491private:
493 enum MotionDriverState {
494 Init0 = 0,
495 WaitForPowerOff = 1,
496 ConfigAg = 2,
497 SelfTestAg = 3,
498 StartDMP = 4,
499 ConfigCompass_0 = 5,
500 ConfigCompass_1 = 6,
501 ConfigCompass_2 = 7,
502 ConfigCompass_3 = 8,
503 ConfigCompass_4 = 9,
504 ConfigCompass_5 = 10,
505 SelfTestCompass = 11,
506 WaitForGyroStable = 12,
507 AdditionalAccelAdjust = 13,
508 Idle = 14,
509 Calibration = 15,
510 LedInstrum = 16,
511 Error = 31,
512 };
514 enum TareType {
515 SetValue = 0x00, AddOffset = 0x01, MatchCompass = 0x02, SetOffset = 0xFF,
516 };
518 struct ResetStats {
519 int32_t resetCount;
520 int32_t resetFlags;
521 int32_t firmVers;
522 bool hasReset;
523 };
524 ResetStats _resetStats = { 0, 0, 0, false };
525
527 void* _handle;
528 uint32_t _deviceNumber;
529 uint32_t _usageHist = 0;
530 uint64_t _cache;
531 uint32_t _len;
532 BasePigeonSimCollection* _simCollection;
533
535 const uint32_t EXPECTED_RESPONSE_TIMEOUT_MS = (200);
536
537 int PrivateSetParameter(ParamEnum paramEnum, TareType tareType,
538 double angleDeg, int timeoutMs = 0);
539
540 double GetTemp(const uint64_t & statusFrame);
541
542protected:
544
545};// class BasePigeon
546} // namespace signals
547} // namespace phoenix
548} // namespace ctre
Definition: CANBusAddressable.h:8
Definition: BasePigeon.h:100
ErrorCode Get6dQuaternion(double wxyz[4]) const
ErrorCode ConfigGetParameter(ParamEnum param, int32_t valueToSend, int32_t &valueReceived, uint8_t &subValue, int32_t ordinal, int32_t timeoutMs)
int GetStatusFramePeriod(PigeonIMU_StatusFrame frame, int timeoutMs=0)
int GetRawGyro(double xyz_dps[3]) const
virtual ErrorCode ConfigFactoryDefault(int timeoutMs=50)
double ConfigGetParameter(ctre::phoenix::ParamEnum param, int ordinal, int timeoutMs=0)
ErrorCode ConfigSetCustomParam(int newValue, int paramIndex, int timeoutMs=0)
ErrorCode ClearStickyFaults(int timeoutMs=0)
int GetBiasedAccelerometer(int16_t ba_xyz[3]) const
BasePigeon(int deviceNumber, std::string const &version, std::string const &canbus="")
int GetAccumGyro(double xyz_deg[3]) const
int GetBiasedMagnetometer(int16_t bm_xyz[3]) const
int SetAccumZAngle(double angleDeg, int timeoutMs=0)
virtual BasePigeonSimCollection & GetSimCollection()
int SetYaw(double angleDeg, int timeoutMs=0)
ErrorCode GetYawPitchRoll(double ypr[3]) const
int ConfigGetCustomParam(int paramIndex, int timeoutMs=0)
int SetYawToCompass(int timeoutMs=0)
void * GetLowLevelHandle() const
Definition: BasePigeon.h:448
int GetRawMagnetometer(int16_t rm_xyz[3]) const
virtual void GetAllConfigs(BasePigeonConfiguration &allConfigs, int timeoutMs=50)
virtual ctre::phoenix::ErrorCode ConfigAllSettings(const BasePigeonConfiguration &allConfigs, int timeoutMs=50)
int AddYaw(double angleDeg, int timeoutMs=0)
ErrorCode SetStatusFramePeriod(PigeonIMU_StatusFrame statusFrame, uint8_t periodMs, int timeoutMs=0)
ErrorCode SetControlFramePeriod(PigeonIMU_ControlFrame frame, int periodMs)
ErrorCode ConfigSetParameter(ParamEnum param, double value, uint8_t subValue, int ordinal, int timeoutMs=0)
Definition: BasePigeonSimCollection.h:22
PigeonIMU_StatusFrame
Definition: PigeonIMU_StatusFrame.h:8
PigeonIMU_ControlFrame
Definition: PigeonIMU_ControlFrame.h:8
ParamEnum
Definition: paramEnum.h:12
ErrorCode
Definition: ErrorCode.h:12
Definition: ErrorCode.h:5
Definition: CustomParamConfiguration.h:10
int customParam1
Definition: CustomParamConfiguration.h:18
bool enableOptimizations
Definition: CustomParamConfiguration.h:22
int customParam0
Definition: CustomParamConfiguration.h:14
std::string toString()
Definition: CustomParamConfiguration.h:33
static bool CustomParam0Different(const BasePigeonConfiguration &settings)
Definition: BasePigeon.h:91
std::string toString()
Definition: BasePigeon.h:62
std::string toString(std::string prependString)
Definition: BasePigeon.h:71