diff --git a/include/ecu_api/ComAPI.h b/include/ecu_api/ComAPI.h new file mode 100644 index 0000000..756a848 --- /dev/null +++ b/include/ecu_api/ComAPI.h @@ -0,0 +1,41 @@ +/* + HOW TO INCLUDE ANOTHER CONNECTION: + 1. Add a ConnectionType and make the IssueCommand call your methods + 2. Generate a WriteXY Method + 2.1 The Parameters can include: commandType, the Command, index, args, response + 2.2 If The Write was successfull set response to "+" + 3. Generate a ReadXY Method + 3.1 The Parameters can include: commandType, command, index, response, isplusminus + 3.2 If the Read was successfull return the result in response +*/ +#ifndef __ComAPI__ +#define __ComAPI__ +#include "Mapping.h" +#include +#include +#include + +typedef struct can_frame can_frame_t; + +class ComAPI +{ +private: + Mapping SeriellToCan; + int handle; + int ConnectionType; + char *IntegerToChar(int in); + Terminal::Connection terminal; + Timer::Connection timer; + + int WriteSerial(std::string str); + int ReadAll(std::string &str); + int ReadSerial(std::string &str, std::string command, bool isplusminuss); +public: + /********************** Functions ****************************/ + int IssueCommand(std::string commandType, int command, int index, std::string args, std::string &response, bool isplusminus = false); + int IssueCommand(std::string commandType, int command, std::string &response, bool isplusminus = false); + /********************** Constructor **************************/ + ComAPI(int ConnectionType); +}; + +#endif diff --git a/include/ecu_api/Constants.h b/include/ecu_api/Constants.h new file mode 100644 index 0000000..db9b66e --- /dev/null +++ b/include/ecu_api/Constants.h @@ -0,0 +1,284 @@ +#ifndef __Constants__ +#define __Constants__ + +/******************** SetCommand Device ********************/ +#define _G 0 + +#define _M 1 +#define _P 2 +#define _S 3 +#define _C 4 +#define _CB 5 + +#define _AC 7 +#define _DC 8 + +#define _DS 9 +#define _D1 10 +#define _D0 11 + +#define _H 13 +#define _EX 14 +#define _MG 15 +#define _MS 16 + +#define _PR 17 +#define _PX 18 +#define _PRX 19 +#define _AX 20 +#define _DX 21 +#define _SX 22 +#define _B 23 +#define _CS 24 + +#define _RC 26 + +#define _EES 27 +#define _BND 28 + + +/******************** SetCommand Alias ********************/ +#define _GO 0 + +#define _MOTCMD 1 +#define _MOTPOS 2 +#define _MOTVEL 3 +#define _SENCNTR 4 +#define _SBLCNTR 5 +#define _VAR 6 + +#define _ACCEL 7 +#define _DECEL 8 + +#define _DOUT 9 +#define _DSET 10 +#define _DRES 11 + +#define _HOME 13 +#define _ESTOP 14 +#define _MGO 15 +#define _MSTOP 16 + +#define _MPOSREL 17 +#define _NXTPOS 18 +#define _NXTPOSR 19 +#define _NXTACC 20 +#define _NXTDEC 21 +#define _NXTVEL 22 +#define _BOOL 23 + + +#define _CANSEND 24 + +#define _RCOUT 26 + +#define _EESAV 27 +#define _BIND 28 + + +/******************** GetValue Device ********************/ +#define _A 0 + +#define _M 1 +#define _P 2 +#define _S 3 +#define _C 4 +#define _CB 5 +#define _VAR 6 +#define _SR 7 +#define _CR 8 +//#define _CBR 9 +#define _BS 10 +#define _BSR 11 +#define _BA 12 +#define _V 13 +#define _D 14 +#define _DI 15 +#define _AI 16 +#define _PI 17 +#define _T 18 +#define _F 19 +#define _FS 20 +#define _FF 21 +//#define _B 22 +#define _DO 23 +#define _E 24 + +#define _CIS 25 +#define _CIA 26 +#define _CIP 27 + +#define _TM 28 + +#define _LK 29 + +#define _K 33 +#define _DR 34 + +#define _AIC 35 +#define _PIC 36 + +#define _MA 38 + +#define _MGD 40 +#define _MGT 41 +#define _MGM 42 +#define _MGS 43 + +/******************** GetValue Alias ********************/ +#define _MOTAMPS 0 + +#define _MOTCMD 1 +#define _MOTPWR 2 +#define _ABSPEED 3 +#define _ABCNTR 4 +#define _BLCNTR 5 +#define _VAR 6 + +#define _RELSPEED 7 +#define _RELCNTR 8 +#define _BLRCNTR 9 +#define _BLSPEED 10 +#define _BLRSPEED 11 +#define _BATAMPS 12 +#define _VOLTS 13 +#define _DIGIN 14 +#define _DIN 15 +#define _ANAIN 16 +#define _PLSIN 17 +#define _TEMP 18 +#define _FEEDBK 19 +#define _STFLAG 20 +#define _FLTFLAG 21 +#define _DIGOUT 23 +#define _LPERR 24 + +#define _CMDSER 25 +#define _CMDANA 26 +#define _CMDPLS 27 + +#define _TIME 28 + +#define _LOCKED 29 +#define _FID 30 +#define _TRN 31 + +#define _SPEKTRUM 33 +#define _DREACHED 34 + +#define _ANAINC 35 +#define _PLSINC 36 + +#define _MEMS 38 + +#define _CAN 39 + +#define _MGDET 40 +#define _MGTRACK 41 +#define _MGMRKR 42 +#define _MGSTATUS 43 + + +/******************** SetConfig/GetConfig Alias ********************/ +#define _EE 0 + +#define _BKD 1 +#define _OVL 2 +#define _UVL 3 +#define _THLD 4 +#define _MXMD 5 +#define _PWMF 6 + +#define _CPRI 7 +#define _RWD 8 +#define _ECHOF 9 +#define _RSBR 10 +#define _ACS 11 +#define _AMS 12 +#define _CLIN 13 +#define _DFC 14 + +#define _DINA 15 +#define _DINL 16 +#define _DOA 17 +#define _DOL 18 + +#define _AMOD 19 +#define _AMIN 20 +#define _AMAX 21 +#define _ACTR 22 +#define _ADB 23 +#define _ALIN 24 +#define _AINA 25 +#define _AMINA 26 +#define _AMAXA 27 +#define _APOL 28 + +#define _PMOD 29 +#define _PMIN 30 +#define _PMAX 31 +#define _PCTR 32 +#define _PDB 33 +#define _PLIN 34 +#define _PINA 35 +#define _PMINA 36 +#define _PMAXA 37 +#define _PPOL 38 + +#define _MMOD 39 +#define _MXPF 40 +#define _MXPR 41 +#define _ALIM 42 +#define _ATRIG 43 +#define _ATGA 44 +#define _ATGD 45 +#define _KP 46 +#define _KI 47 +#define _KD 48 +#define _PIDM 49 +#define _ICAP 50 +#define _MAC 51 +#define _MDEC 52 +#define _MVEL 53 +#define _MXRPM 54 +#define _MXTRN 55 +#define _CLERD 56 + +#define _BPOL 57 +#define _BLSTD 58 +#define _BLFB 59 +#define _BHOME 60 +#define _BLL 61 +#define _BHL 62 +#define _BLLA 63 +#define _BHLA 64 + +#define _SXC 65 +#define _SXM 66 + +#define _TELS 70 +#define _BRUN 71 +#define _EMOD 72 +#define _EPPR 73 +#define _ELL 74 +#define _EHL 75 +#define _ELLA 76 +#define _EHLA 77 +#define _EHOME 78 + +#define _SKUSE 79 +#define _SKMIN 80 +#define _SKMAX 81 +#define _SKCTR 82 +#define _SKDB 83 +#define _SKLIN 84 + +#define _CEN 85 +#define _CNOD 86 +#define _CBR 87 +#define _CHB 88 +#define _CAS 89 +#define _CLSN 90 +#define _CSRT 91 + +#endif diff --git a/include/ecu_api/CoreAPI.h b/include/ecu_api/CoreAPI.h new file mode 100644 index 0000000..9facda5 --- /dev/null +++ b/include/ecu_api/CoreAPI.h @@ -0,0 +1,223 @@ +// PROTOTYPE SETTER: +// int SetSomething(int PORT, int VALUE) +// int status = RQ_INVALID_CONFIG_ITEM; +// if (CheckRange(PORT, MIN, MAX) && CheckRange(VALUE, MIN, MAX)) +// status = device.SetCommand(CMD, PORT, VALUE); +// return status; +// +// PROTOTYPE GETTER: +// int GetSomething(int PORT, int& VALUE) +// int status = RQ_INVALID_CONFIG_ITEM; +// if (CheckRange(PORT, MIN, MAX)) +// status = device.GetConfig(CMD, PORT, VALUE); +// return status; +// +// Also dont use block comments + +#ifndef __CoreAPI__ +#define __CoreAPI__ + +#include "RoboteqDevice.h" + +class CoreAPI +{ +private: + RoboteqDevice device; + inline bool CheckRange(int val, int min, int max); + inline bool CheckMotor(int mot); + inline void ExtractDINA(int mot, int &val); +protected: +public: + /*****************************************************/ + int SetMotorSpeedAccel(int speed, int accel); + int SetMotorSpeedDecel(int speed, int decel); + int SetMotorSpeedRel(int speed); + int SetMotorSpeedAbs(int speed); + + int SetAbsoluteDesiredPosition(int port, int value); + int SetMotorPositionVelocity(int port, int value); + int SetNextPositionVelocity(int port, int value); + int SetEncoderCounter(int port, int value); + int SetBrushlessCounter(int port, int value); + int SetUserIntegerVariables(int num, int value); + int SetUserIntegerBool(int num, int value); + int SetAcceleration(int port, int accel); + int SetNextAcceleration(int port, int accel); + int SetDeceleration(int port, int decel); + int SetNextDeceleration(int port, int decel); + int SetDigitalOuts(int port); + int SetResetDigitalOuts(int port); + int SetLoadHomeCounter(int port); + int SetEmergencyStop(); + int SetReleaseEmergencyStop(); + int SetEmergencyStop(int port); + int SetRelativeDesiredPosition(int port, int value); + int SetNextAbsoluteDesiredPosition(int port, int value); + int SetNextRelativeDesiredPosition(int port, int value); + int SetSaveConfig(); + + // CONFIG + int SetScriptingAutostart(int val); + int SetAnalogCenterSafety(int val); + int SetChannelPriorities(int port, int val); + int SetSerialTimout(int val); + int SetLinearity(int val); + int SetAnalogMinMaxSafety(int val); + int SetEncoderMode(int mot, int val); + int SetEncoderPPR(int val); + int SetEncoderLowLimitCount(int val); + int SetEncoderHighLimitCount(int val); + int SetEncoderCounterLoadAtHomePosition(int val); + int SetEncoderLowLimitAction(int mot, int val); + int SetEncoderHighLimitAction(int mot, int val); + int SetDigitalInput(int port, int val); + int SetDigitalInputAction(int port, int mot, int val); + int SetAnalogInputMode(int port, int val); + int SetAnalogInputAction(int port, int mot, int val); + int SetAnalogInputMin(int port, int val); + int SetAnalogInputCenter(int port, int val); + int SetAnalogInputMax(int port, int val); + int SetAnalogInputPolarity(int port, int val); + int SetAnalogDeadband(int port, int val); + int SetAnalogMinAction(int port, int mot, int val); + int SetAnalogMaxAction(int port, int mot, int val); + int SetPulseInputMode(int port, int val); + int SetPulseInputAction(int port, int mot, int val); + int SetPulseMin(int port, int val); + int SetPulseMax(int port, int val); + int SetPulseCenter(int port, int val); + int SetPulseDeadbeand(int port, int val); + int SetPulseMinAction(int port, int mot, int val); + int SetPulseMaxAction(int port, int mot, int val); + int SetPulseLinearity(int port, int val); + int SetDigitalOutputActiveLevel(int port, int val); + int SetDigitalOutputAction(int port, int mot, int val); + int SetPWMFrequency(int val); + int SetOvervoltageLimit(int val); + int SetUndervoltageLimit(int val); + int SetBrakeActivationDelay(int val); + int SetShortCircuitThreshold(int val); + int SetNumPoles(int mot, int val); + int SetBrushlessFeedback(int mot, int val); + int SetBrushlessStallDetection(int mot, int val); + int SetEncoderLowLimit(int mot, int val); + int SetEncoderHighLimitAction(int port, int mot, int val); + int SetEncoderLowLimitAction(int port, int mot, int val); + int SetMotorAmpsLimit(int val); + int SetMotorAmpsTriggerValue(int val); + int SetMotorAmpsTriggerAction(int mot, int val); + int SetMotorAmpsTriggerDelay(int val); + int SetMotorMaxPowerForward(int val); + int SetMotorMaxPowerReverse(int val); + int SetMotorMaxRPM(int val); + int SetMotorOperatingMode(int val); + int SetMotorDefaultVelocity(int val); + int SetMotorMaxTurns(int val); + int SetProportionalGain(int val); + int SetIntegrationalGain(int val); + int SetDifferentialGain(int val); + int SetMotorIntCap(int val); + int SetLoopErrorMode(int val); + + //int SetTelemetryString(std::string &str); + //int SetEncoderHighLimit(int mot, int val); + //int SetBrushlessHomeCounter(int mot, int val); + /******************************************************/ + int GetMotorPower(int &power); + int GetMotorRPM(int &rpm); + int GetMotorAmps(int &s); + int GetBatteryVolt(int &volt); + int GetControllerVolt(int &volt); + int Get5VOutput(int &volt); + int GetMotorTemperature(int &temp); + int GetMCUTemperature(int &temp); + // CONFIG + int GetMotorControllerType(std::string &val); + int GetMotorControllerFirmware(std::string &val); + int GetLoopError(int &val); + int GetScriptingAutostart(int &val); + int GetAnalogCenterSafety(int &val); + int GetTelemetryString(std::string &str); + int GetChannelPriorities(int port, int &val); + int GetSerialTimeout(int &val); + int GetLinearity(int &val); + int GetAnalogMinMaxSafety(int &val); + int GetBrushlessCountRelative(int &val); + int GetEncoderMode(int mot, int &val); + int GetEncoderPPR(int &val); + int GetEncoderLowLimitCount(int &val); + int GetEncoderHighLimitCount(int &val); + int GetEncoderCounterLoadAtHomePosition(int &val); + int GetEncoderLowLimitAction(int mot, int &val); + int GetEncoderHighLimitAction(int mot, int &val); + int GetDigitalInput(int port, int &val); + int GetDigitalInputAction(int port, int mot, int &val); + int GetAnalogInputMode(int port, int &val); + int GetAnalogInputAction(int port, int &val); + int GetAnalogInputMin(int port, int &val); + int GetAnalogInputCenter(int port, int &val); + int GetAnalogInputMax(int port, int &val); + int GetAnalogInputPolarity(int port, int &val); + int GetAnalogDeadband(int port, int &val); + int GetAnalogMinAction(int port, int &val); + int GetAnalogMaxAction(int port, int &val); + int GetPulseInputMode(int port, int &val); + int GetPulseInputAction(int port, int mot, int &val); + int GetPulseMin(int port, int &val); + int GetPulseMax(int port, int &val); + int GetPulseCenter(int port, int &val); + int GetPulseDeadbeand(int port, int &val); + int GetPulseMinAction(int port, int mot, int &val); + int GetPulseMaxAction(int port, int mot, int &val); + int GetPulseLinearity(int port, int &val); + int GetDigitalOutputActiveLevel(int port, int &val); + int GetDigitalOutputAction(int port, int mot, int &val); + int GetPWMFrequency(int &val); + int GetOvervoltageLimit(int &val); + int GetUndervoltageLimit(int &val); + int GetBrakeActivationDelay(int &val); + int GetShortCircuitThreshold(int &val); + int GetNumPoles(int mot, int &val); + int GetBrushlessFeedback(int mot, int &val); + int GetBrushlessStallDetection(int mot, int &val); + int GetEncoderLowLimit(int mot, int &val); + int GetEncoderHighLimit(int mot, int &val); + int GetBrushlessHomeCounter(int mot, int &val); + int GetEncoderHighLimitAction(int port, int mot, int &val); + int GetEncoderLowLimitAction(int port, int mot, int &val); + int GetMotorAmpsLimit(int &val); + int GetMotorAmpsTriggerValue(int &val); + int GetMotorAmpsTriggerAction(int mot, int &val); + int GetMotorAmpsTriggerDelay(int &val); + int GetMotorMaxPowerForward(int &val); + int GetMotorMaxPowerReverse(int &val); + int GetMotorMaxRPM(int &val); + int GetAcceleration(int &val); + int GetDeacceleration(int &val); + int GetMotorOperatingMode(int &val); + int GetMotorDefaultVelocity(int &val); + int GetMotorMaxTurns(int &val); + int GetProportionalGain(int &val); + int GetIntegrationalGain(int &val); + int GetDifferentialGain(int &val); + int GetMotorIntCap(int &val); + int GetLoopErrorMode(int &val); + + int GetAbsoluteDesiredPosition(int port, int &value); + int GetMotorPositionVelocity(int port, int &value); + int GetEncoderCounter(int port, int &value); + int GetBrushlessCounter(int port, int &value); + int GetUserIntegerVariables(int num, int &value); + int GetUserIntegerBool(int num, int &value); + int GetDigitalOuts(int port, int &value); + + bool IsConnected(); + + // TODO + //int GetNextPositionVelocity(int port, int &value); + /********************** Constructor **************************/ + CoreAPI(int ConnectionType); + ~CoreAPI(); +}; + +#endif diff --git a/include/ecu_api/Defines.h b/include/ecu_api/Defines.h new file mode 100644 index 0000000..200340d --- /dev/null +++ b/include/ecu_api/Defines.h @@ -0,0 +1,117 @@ +/********** BRUN ***************/ +#define BRUN_DISABLED 0 +#define BRUN_DELAYED 1 +#define BRUN_ACTIVATED 2 + +/******** Command Priorities *******/ +#define CPRI_DISABLED 0 +#define CPRI_SERIAL 1 +#define CPRI_RC 2 +#define CPRI_ANALOG 3 + +/********* Linearity **************/ +#define LIN_LINEAR 0 +#define LIN_EXP_WEAK 1 +#define LIN_EXP_MEDIUM 2 +#define LIN_EXP_STRONG 3 +#define LIN_LOG_WEAK 4 +#define LIN_LOG_MEDIUM 5 +#define LIN_LOG_STRONG 6 + +/******** Encode Usage ************/ +#define ENC_UNUSED 0 +#define ENC_COMMAND 1 +#define ENC_FEEDBACK 2 + +/*********** Motor Numbers ********/ +#define MOT1 16 +#define MOT2 32 +#define MOT12 48 + +/************ DINA ****************/ +#define DINA_NO_ACTION 0 +#define DINA_SAFETY_STOP 1 +#define DINA_EMERGENCY_STOP 2 +#define DINA_MOTOR_STOP 3 +#define DINA_FORWARD_LIMIT_SWITCH 4 +#define DINA_REVERSE_LIMIT_SWITCH 5 +#define DINA_INVERT_DIRECTION 6 +#define DINA_RUN_MICROBASIC 7 +#define DINA_LOAD_HOME_VALUE 8 +#define DINA_MOT1 32 +#define DINA_MOT2 64 +#define DINA_MOT12 96 + +/************ AMOD ****************/ +#define AMOD_DISABLED 0 +#define AMOD_ABSOLUTE 1 +#define AMOD_RELATIVE 2 + +/********** Polarity **************/ +#define APOL_UNINVERTED 0 +#define APOL_INVERTED 1 + +/************* Deadband ************/ +#define DB_MIN 0 +#define DB_MAX 50 + +/************* Pulse Mode **********/ +#define PMOD_DISABLED 0 +#define PMOD_PULSE_WIDTH 1 +#define PMOD_FREQUENCY 2 +#define PMOD_PERIOD 3 + +/********* Digital Output ***********/ +#define DOL_ACTIVE_HIGH 0 +#define DOL_ACTIVE_LOW 1 + +#define DOA_NO_ACTION 0 +#define DOA_MOTOR_ON 1 +#define DOA_OVERVOLTAGE 2 +#define DOA_OVERTEMPERATURE 3 +#define DOA_MIRROR_STATUS_LED 4 +#define DOA_NO_MOSFET_FAILURE 5 + +/********** Short Circuit **********/ +#define THLD_HIGH_SENSITIVITY 0 +#define THLD_MEDIUM_SENSITIVITY 1 +#define THLD_LOW_SENSITIVITY 2 +#define THLD_DISABLED 3 + +/********* Feedback **************/ +#define BLFB_HALL_SENSOR 0 +#define BLFB_ENCODER 1 + +/********* Stall Detection *******/ +#define BLSTD_DISABLED 0 +#define BLSTD_250MS_OVER_10 1 +#define BLSTD_500OMS_0VER_25 2 +#define BLSTD_1000MS_OVER_50 3 + +/****** Motor Operatin Mode ******/ +#define MMOD_OPEN_LOOP_SPEED 0 +#define MMOD_CLOSED_LOOP_SPEED 1 +#define MMOD_CLOSED_LOOP_POSITION_RELATIVE 2 +#define MMOD_closed_LOPP_COUNT_POSITION 3 +#define MMOD_CLOSED_LOOP_POSITION_TRACKING 4 +#define MMOD_TORQUE 5 + +/********* LOOP ERROR Detection *******/ +#define CLERD_DISABLED 0 +#define CLERD_250msGreater100 1 +#define CLERD_500msGreater250 2 +#define CLERD_1000msGreater500 3 + +/************** General ***************/ +#define MAX_DIGITAL_INPUTS 6 +#define MAX_ANALOG_INPUTS 6 +#define MAX_DIGITAL_OUTPUTS 2 +#define MAX_OVERVOLTAGE 500 + + +/*************** COM *******************/ +#define CONNECTION_USB 0 +#define CONNECTION_CAN 1 +#define CONNECTION_COM 2 + +#define MAX_RPM 2500 diff --git a/include/ecu_api/ErrorCodes.h b/include/ecu_api/ErrorCodes.h new file mode 100644 index 0000000..029629b --- /dev/null +++ b/include/ecu_api/ErrorCodes.h @@ -0,0 +1,23 @@ +#ifndef __ErrorCodes_H_ +#define __ErrorCodes_H_ + +#define RQ_INVALID_HANDLE -1 +#define RQ_SUCCESS 0 +#define RQ_ERR_OPEN_PORT 1 +#define RQ_ERR_NOT_CONNECTED 2 +#define RQ_ERR_TRANSMIT_FAILED 3 +#define RQ_ERR_SERIAL_IO 4 +#define RQ_ERR_SERIAL_RECEIVE 5 +#define RQ_INVALID_RESPONSE 6 +#define RQ_UNRECOGNIZED_DEVICE 7 +#define RQ_UNRECOGNIZED_VERSION 8 +#define RQ_INVALID_CONFIG_ITEM 9 +#define RQ_INVALID_OPER_ITEM 10 +#define RQ_INVALID_COMMAND_ITEM 11 +#define RQ_INDEX_OUT_RANGE 12 +#define RQ_SET_CONFIG_FAILED 13 +#define RQ_GET_CONFIG_FAILED 14 +#define RQ_GET_VALUE_FAILED 15 +#define RQ_SET_COMMAND_FAILED 16 + +#endif diff --git a/include/ecu_api/Mapping.h b/include/ecu_api/Mapping.h new file mode 100644 index 0000000..4a8076a --- /dev/null +++ b/include/ecu_api/Mapping.h @@ -0,0 +1,13 @@ +#ifndef __MAPPING__ +#define __MAPPING__ + +typedef unsigned char __u8; +class Mapping{ + public: + __u8 GetReadMapping(int cmd); + __u8 GetWriteMapping(int cmd); + Mapping(); + ~Mapping(); +}; + +#endif diff --git a/include/ecu_api/RoboteqDevice.h b/include/ecu_api/RoboteqDevice.h new file mode 100644 index 0000000..85e2697 --- /dev/null +++ b/include/ecu_api/RoboteqDevice.h @@ -0,0 +1,34 @@ +#ifndef __RoboteqDevice_H_ +#define __RoboteqDevice_H_ + +#include "ComAPI.h" + +class RoboteqDevice +{ +private: + ComAPI com; +public: + bool IsConnected(); + void Disconnect(); + + int SetConfig(int configItem, int index, int value); + int SetConfig(int configItem, int value); + int SetRawConfig(int configItem, std::string str); + + int SetCommand(int commandItem, int index, int value); + int SetCommand(int commandItem, int value); + int SetCommand(int commandItem); + + int GetConfig(int configItem, int index, int &result); + int GetConfig(int configItem, int &result); + int GetRawConfig(int configItem, std::string &result); + + int GetValue(int operatingItem, int index, int &result); + int GetValue(int operatingItem, int &result); + int GetRawValue(int operatingItem, std::string &result); + + RoboteqDevice(int type); + ~RoboteqDevice(); +}; + +#endif diff --git a/lib/mk/ecu_api.mk b/lib/mk/ecu_api.mk new file mode 100644 index 0000000..19f6318 --- /dev/null +++ b/lib/mk/ecu_api.mk @@ -0,0 +1,7 @@ +SRC_CC = RoboteqDevice.cpp ComAPI.cpp CoreAPI.cpp Mapping.cpp + +LIBS = base stdcxx + +REP_INC_DIR += include/ecu_api + +vpath % $(REP_DIR)/src/lib/ecu_api diff --git a/src/lib/ecu_api/ComAPI.cpp b/src/lib/ecu_api/ComAPI.cpp new file mode 100644 index 0000000..33cd130 --- /dev/null +++ b/src/lib/ecu_api/ComAPI.cpp @@ -0,0 +1,126 @@ +#include "ComAPI.h" + +#include "Constants.h" +#include "ErrorCodes.h" +#include "Defines.h" + +#include +#include +#include +#include +#include +#include +#include + + +using namespace std; +#define BUFFER_SIZE 1024 + +ComAPI::ComAPI(int ConnectionType) : timer(), terminal(), SeriellToCan() +{ + handle = RQ_INVALID_HANDLE; + ComAPI::ConnectionType = ConnectionType; +} + +/********************** Functions *****************************/ +/** + * Writes to the device + * @param str Stuff that needs to be written + * @return RQ Status Flags + */ +int ComAPI::WriteSerial(std::string str) +{ + size_t countSent = terminal.write(str.c_str(), str.length()); + + //Verify whether the Transmitted Data on UART was Successful or Not + if (countSent < str.length()) + return RQ_ERR_TRANSMIT_FAILED; + + return RQ_SUCCESS; +} +/** + * Reads from the Serial Port + */ +int ComAPI::ReadSerial(std::string &str, std::string command, bool isplusminus) +{ + int countRcv; + + char buf[BUFFER_SIZE + 1] = ""; + + str = ""; + countRcv = terminal.read(buf, BUFFER_SIZE); + str.append(buf, countRcv); + + if (countRcv < 0) + { + return RQ_ERR_SERIAL_RECEIVE; + } + + if (isplusminus) + { + if (str.length() < 2) + return RQ_INVALID_RESPONSE; + + str = str.substr(str.length() - 2, 1); + return RQ_SUCCESS; + } + + std::string::size_type pos = str.rfind(command + "="); + if (pos == std::string::npos) + return RQ_INVALID_RESPONSE; + + pos += command.length() + 1; + + std::string::size_type carriage = str.find("\r", pos); + if (carriage == std::string::npos) + return RQ_INVALID_RESPONSE; + + str = str.substr(pos, carriage - pos); + + return RQ_SUCCESS; +} + +/** + * Calls the IssueCommand(std::string, std::string, std::string, std::string&,bool) Method + * @param commandType CommandTypes: !,?,~,^ (SetCommand, GetValue, GetConfig,SetConfig) + * @param command The Command to be Executed + * @param index The Index of the Command + * @param args Arguments for the command + * @param response Return value + * @param isplusminus Get expects a '=' while Set expects an '+' or '-' + * @return RQ Status Flags + */ +int ComAPI::IssueCommand(std::string commandType, int command, int index, std::string args, std::string &response, bool isplusminus) +{ + int status = RQ_UNRECOGNIZED_DEVICE; + response = ""; + if (ConnectionType == CONNECTION_USB + || ConnectionType == CONNECTION_COM) + { + char commandItem[10]; + // Command to hex + sprintf(commandItem, "$%02X", command); + // Write Command To Device + string test = commandType + commandItem + " " + to_string(index) + (args == "" ? "" : " " + args) + "\r"; + if ((status = WriteSerial(commandType + commandItem + " " + to_string(index) + (args == "" ? "" : " " + args) + "\r")) != RQ_SUCCESS) + return RQ_ERR_TRANSMIT_FAILED; + // **** Wait + timer.msleep(10); + // **** Read from Port + return ReadSerial(response, commandItem, isplusminus); + } + else + return status; +} +/** + * Calls the IssueCommand(std::string, std::string, std::string, std::string&,bool) Method + * @param commandType CommandTypes: !,?,~,^ (SetCommand, GetValue, GetConfig,SetConfig) + * @param command The Command to be Executed + * @param response Return value + * @param isplusminus Get expects a '=' while Set expects an '+' or '-' + * @return RQ Status Flags + */ +int ComAPI::IssueCommand(std::string commandType, int command, std::string &response, bool isplusminus) +{ + return IssueCommand(commandType, command, 0, "", response, isplusminus); +} diff --git a/src/lib/ecu_api/CoreAPI.cpp b/src/lib/ecu_api/CoreAPI.cpp new file mode 100644 index 0000000..4c1efed --- /dev/null +++ b/src/lib/ecu_api/CoreAPI.cpp @@ -0,0 +1,2231 @@ +#include "CoreAPI.h" + +#include +#include +#include + +#include "ErrorCodes.h" +#include "Constants.h" +#include "Defines.h" + +/**************************************************************/ +/************************ Constructor *************************/ +/**************************************************************/ +CoreAPI::CoreAPI(int ConnectionType) : device(ConnectionType) +{} +CoreAPI::~CoreAPI() {} + +/**************************************************************/ +/************************ SETTER ******************************/ +/**************************************************************/ +/**************************************************************/ +/************************ RUNTIME *****************************/ +/**************************************************************/ +/** +* Sets the maximum acceleration and sets the speed step by step +* @param speed Resulting Speed +* @param accel Acceleration +* @return RRQ Status Flags +*/ +int CoreAPI::SetMotorSpeedAccel(int speed, int accel) +{ + int status; + if ((status = CoreAPI::SetAcceleration(1, accel)) != RQ_SUCCESS) + return RQ_INVALID_RESPONSE; + + if ((status = CoreAPI::SetMotorSpeedAbs(speed)) != RQ_SUCCESS) + return RQ_INVALID_RESPONSE; + + return RQ_SUCCESS; +} +/** +* Lowers Motorspeed to speed descending according to decel +* @param speed Desired speed +* @param decel Deacceleration +* @return RQ Status Flags +*/ +int CoreAPI::SetMotorSpeedDecel(int speed, int decel) +{ + int status; + if ((status = CoreAPI::SetDeceleration(1, decel)) != RQ_SUCCESS) + return RQ_INVALID_RESPONSE; + + if ((status = CoreAPI::SetMotorSpeedAbs(speed)) != RQ_SUCCESS) + return RQ_INVALID_RESPONSE; + + return RQ_SUCCESS; +} +/** +* Sets Motorspeed according to a value between 0 and 1000 +* @param speed Desired Speed +* @return RQ Status Flags +*/ +int CoreAPI::SetMotorSpeedRel(int speed) +{ + int status = device.SetCommand(_MOTCMD, speed); + return status; +} +/** +* Sets the Motorspeed in RPM +* @param speed Desired Speed in RPM +* @return RQ Status Flags +*/ +int CoreAPI::SetMotorSpeedAbs(int speed) +{ + int status = device.SetCommand(_GO, 1, speed); + return status; +} +/** + * \test + * (_P) see p. 169 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetAbsoluteDesiredPosition(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) + && CheckRange(value, CPRI_DISABLED, CPRI_ANALOG)) + status = device.SetCommand(_P, port, value); + return status; +} +/** + * \test + * (_S) see p. 171 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetMotorPositionVelocity(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) && CheckRange(value, 0, MAX_RPM)) + status = device.SetCommand(_S, port, value); + return status; +} +/** + * \test + * (_SX) see p. 171 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetNextPositionVelocity(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) + && CheckRange(value, 0, MAX_RPM)) + status = device.SetCommand(_SX, port, value); + return status; +} +/** + * \test + * (_C) see p. 166 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetEncoderCounter(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_C, port, value); + return status; +} +/** + * \test + * (_CB) see p. 166 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetBrushlessCounter(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_CB, port, value); + return status; +} +/** + * \test + * Sets the User Variables (_VAR) see p. 171 + * @param num Number 0 - 16 + * @param value Integer Value to Set + * @return RQ Status Flags + */ +int CoreAPI::SetUserIntegerVariables(int num, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(num, 0, 16)) + status = device.SetCommand(_VAR, num, value); + return status; +} +/** + * \test + * Sets the User Variables (_B) see p. 165 + * @param num Number 0 - 16 + * @param value Integer Value to Set + * @return RQ Status Flags + */ +int CoreAPI::SetUserIntegerBool(int num, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(num, 0, 32)) + status = device.SetCommand(_B, num, value); + return status; +} +/** + * \test + * Sets the Acceleration ( _AC) see p. 165 + * @param port Motor 1 or 2 + * @param value Acceleration + * @return RQ Status Flags + */ +int CoreAPI::SetAcceleration(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_AC, port, value); + return status; +} +/** + * \test + * Sets the next Acceleration ( _AX) see p.165 + * @param port Motor 1 or 2 + * @param value Acceleration + * @return RQ Status Flags + */ +int CoreAPI::SetNextAcceleration(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_AX, port, value); + return status; +} +/** + * \test + * Sets the Deacceleration ( _DC) see p.167 + * @param port Motor 1 or 2 + * @param value Acceleration + * @return RQ Status Flags + */ +int CoreAPI::SetDeceleration(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_DC, port, value); + return status; +} +/** + * \test + * Sets the next Deacceleration ( _DX) see p.168 + * @param port Motor 1 or 2 + * @param value Acceleration + * @return RQ Status Flags + */ +int CoreAPI::SetNextDeceleration(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_DX, port, value); + return status; +} +/** + * \test + * Enables the Digital Outputs ( _D1) see p.167 + * @param port Outputs: 0 - MAX_DIGITAL_OUTPUTS + * @return RQ Status Flags + */ +int CoreAPI::SetDigitalOuts(int port) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS)) + status = device.SetCommand(_D1, port); + return status; +} +/** + * \test + * Reset the Digital Outputs ( _D0) see p.167 + * @param port Outputs: 0 - MAX_DIGITAL_OUTPUTS + * @return RQ Status Flags + */ +int CoreAPI::SetResetDigitalOuts(int port) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS)) + status = device.SetCommand(_D0, port); + return status; +} +/** + * \test + * (_H) see p.169 + * @param port Port + * @return RQ Status Flags + */ +int CoreAPI::SetLoadHomeCounter(int port) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_H, port); + return status; +} +/** + * \test + * Trigger Emeregency Stop (_EX) see p.168 + * @return RQ Status Flags + */ +int CoreAPI::SetEmergencyStop() +{ + return device.SetCommand(_EX, 0, 0);; +} +/** + * \test + * Release Emergency Stop (_MG) see p.169 + * @return RQ Status Flags + */ +int CoreAPI::SetReleaseEmergencyStop() +{ + return device.SetCommand(_MG, 0, 0); +} +/** + * \test + * Trigger Emeregency Stop on specified Motor (_MS) see p.169 + * @param port Motor: 1 or 2 + * @return RQ Status Flags + */ +int CoreAPI::SetEmergencyStop(int port) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_MS, port); + return status; +} +/** + * \test + * (_PR) see p.170 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetRelativeDesiredPosition(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_PR, port, value); + return status; +} +/** + * \test + * (_PX) see p.170 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetNextAbsoluteDesiredPosition(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_PX, port, value); + return status; +} +/** + * (_PRX) see p.170 + * @param port Port + * @param value Value + * @return RQ Status Flags + */ +int CoreAPI::SetNextRelativeDesiredPosition(int port, int value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.SetCommand(_PRX, port, value); + return status; +} +/** + * \test + * Saves the Config to the Flash (_EES) see p.168 + * @return RQ Status Flags + */ +int CoreAPI::SetSaveConfig() +{ + return device.SetCommand(_EES, 0); +} +/**************************************************************/ +/************************ CONFIG ******************************/ +/**************************************************************/ + +/** +* Sets the Scripting Autostart Mode (_BRUN) see p.196 +* @param val BRUN_DISABLED | BRUN_DELAYED | BRUN_ACTIVATED +* @return RQ Status Flags +*/ +int CoreAPI::SetScriptingAutostart(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, BRUN_DISABLED, BRUN_ACTIVATED) ) + status = device.SetConfig(_BRUN, val); + return status; +} +/** +* Sets the Linearity (_CLIN) see p.197 +* @param val LIN_LINEAR | LIN_EXP_WEAK | LIN_EXP_MEDIUM | LIN_EXP_STRONG | LIN_LOG_WEAK | LIN_LOG_MEDIUM | LIN_LOG_STRONG +* @return RQ Status Flags +*/ +int CoreAPI::SetLinearity(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, LIN_LINEAR, LIN_LOG_STRONG)) + status = device.SetConfig(_CLIN, val); + return status; +} +/** +* Sets the Serial Timout (_RWD) see p.198 +* @param val Range: 0 - 65000 +* @return RQ Status Flags +*/ +int CoreAPI::SetSerialTimout(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 0, 6500)) + status = device.SetConfig(_RWD, val); + return status; +} +/** +* Sets the ChannelPriorities (_CPRI) p.197 +* @param port Port: 1 - 3 +* @param val CPRI_DISABLED | CPRI_SERIAL | CPRI_RC | CPRI_ANALOG +* @return RQ Status Flags +*/ +int CoreAPI::SetChannelPriorities(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 3) + && CheckRange(val, CPRI_DISABLED, CPRI_ANALOG)) + status = device.SetConfig(_CPRI, port, val); + return status; +} +/*int CoreAPI::SetTelemetryString(std::string &str) +{ + return device.SetRawConfig(_TELS, str); +}*/ +/** +* Sets the AnalogCenterSafety (_ACS) see p. 196 +* @param value sets ACS +* @return RQ Status Flags +*/ +int CoreAPI::SetAnalogCenterSafety(int value) +{ + return device.SetConfig(_ACS, value); +} +/** +* Sets Analog within Min & Max Safety (_AMS) see p. 196 +* @param val Sets AMS +* @return RQ Status Flags +*/ +int CoreAPI::SetAnalogMinMaxSafety(int val) +{ + return device.SetConfig(_AMS, val); +} +/** +* Sets the Encoder Usage (_EMOD) see p. 210 +* @param mot Motor: MOT1 | MOT2 +* @param val Desired Value: ENC_UNUSED | ENC_COMMAND | ENC_FEEDBACK +* @return RQ Status Flags +*/ +int CoreAPI::SetEncoderMode(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, ENC_UNUSED, ENC_FEEDBACK)) + status = device.SetConfig(_EMOD, mot + val); + return status; +} +/** +* Set the Encoder PPR Value (_EPPR) see p.210 +* @param val Desired Value: Range 1 - 5000 default: 100 +* @return RQ Status Flags +*/ +int CoreAPI::SetEncoderPPR(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 1, 5000)) + status = device.SetConfig(_EPPR, val); + return status; +} +/** +* Encoder Low Count Limit (_ELL) see p.209 +* @param val Desired Value +* @return RQ Status Flags +*/ +int CoreAPI::SetEncoderLowLimitCount(int val) +{ + return device.SetConfig(_ELL, val); +} +/** +* Encoder High Count Limit (_EHL) see p.208 +* @param val Desired Value +* @return RQ Status Flags +*/ +int CoreAPI::SetEncoderHighLimitCount(int val) +{ + return device.SetConfig(_EHL, val); +} +/** +* Encoder Counter Load at Home Position (_EHOME) see p.209 +* @param val Desired Value +* @return RQ Status Flags +*/ +int CoreAPI::SetEncoderCounterLoadAtHomePosition(int val) +{ + return device.SetConfig(_EHOME, val); +} +/** +* Gets the Encoder High Limit Action (_EHLA) see p.209 +* @param mot Motor: MOT1 | MOT2 +* @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE +* @return RQ_Status_Flags +*/ +int CoreAPI::SetEncoderLowLimitAction(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE) + && CheckMotor(mot)) + status = device.SetConfig(_ELLA, mot + val); + return status; +} + +/** +* Gets the Encoder High Limit Action (_EHLA) see p.209 +* @param mot Motor: MOT1 | MOT2 +* @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE +* @return RQ_Status_Flags +*/ +int CoreAPI::SetEncoderHighLimitAction(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE) + && CheckMotor(mot)) + status = device.SetConfig(_EHLA, mot + val); + return status; +} +/** + * Set the Digital Inputs for each port (_DINL) see p. 200 + * @param port Port number 0 - MAX_DIGITAL_INPUTS + * @param val Desired Value: 0 -> active low, 1 -> active high + * @return RQ Status Flags + */ +int CoreAPI::SetDigitalInput(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_INPUTS) && CheckRange(val, 0, 1)) + status = device.SetConfig(_DINL, port, val); + return status; +} +/** + * Sets the Digital Input Action if a port is triggered (_DINA) see p.199 + * @param port Port: 0 - MAX_DIGITAL_INPUTS + * @param mot Motor: DINA_MOT1 || DINA_MOT2 || DINA_MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::SetDigitalInputAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if ((mot == DINA_MOT1 || mot == DINA_MOT2 || mot == DINA_MOT12) && + CheckRange(port, 0, MAX_DIGITAL_INPUTS) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE)) + status = device.SetConfig(_DINA, port, val + mot); + return status; +} +/** + * Sets the Analog Input Mode (_AMOD) see p.204 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val AMOD Values: AMOD_DISABLED | AMOD_ABSOLUTE | AMOD_RELATIVE + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogInputMode(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, AMOD_DISABLED, AMOD_RELATIVE)) + status = device.SetConfig(_AMOD, port, val); + return status; +} + +/** + * Sts the Analog Input Actions for each port (_AINA) see p.202 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val Returns the USAGE: ENC_UNUSED | ENC_COMMAND | ENC_FEEDBACK + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogInputAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, ENC_UNUSED, ENC_FEEDBACK) + && CheckMotor(mot)) + status = device.SetConfig(_AINA, port, mot + val); + return status; +} +/** + * Set Analog Input Range for each Point (_AMIN) see p. 203 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Min: 0 - 5000 mV default: 100mV + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogInputMin(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, 0, 5000)) + status = device.SetConfig(_AMIN, port, val); + return status; +} +/** + * Sets the Analog Input Center (_ACTR) see p. 201 + * @param port Port: 0 - MAX_ANALOG_INPUT + * @param val Center: 0 - 5000 default: 2500 + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogInputCenter(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, 0, 5000)) + status = device.SetConfig(_ACTR, port, val); + return status; +} +/** + * Sets the Analog Input Max (_AMAX) see p. 203 + * @param port Port: 0 - MAX_ANALOG_INPUT + * @param val Max: 0 - 5000 default: 4900 + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogInputMax(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.SetConfig(_AMAX, port, val); + return status; +} +/** + * Sets the Analog Input Polarity for every port (_APOL) see p.204 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Polarity: APOL_UNINVERTED | APOL_INVERTED + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogInputPolarity(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, APOL_UNINVERTED, APOL_INVERTED)) + status = device.SetConfig(_APOL, port, val); + return status; +} +/** + * Sets the Analog Deadband (_ADB) see p.201 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Deadband: 0 - 50 + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogDeadband(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, DB_MIN, DB_MAX)) + status = device.SetConfig(_ADB, port, val); + return status; +} +/** + * Sets the Action on Analog Min (_AMINA) see p.201 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogMinAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE) + && CheckMotor(mot)) + status = device.SetConfig(_AMINA, port, mot + val); + return status; +} +/** + * Sets the Action on Analog Max (_AMAXA) see p.201 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::SetAnalogMaxAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE) + && CheckMotor(mot)) + return device.SetConfig(_AMAXA, port, mot + val); + return status; +} +/** + * Sets the Pulse Input Mode (_PMOD) see p. 207 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val PM Values: PMOD_DISABLED | PMOD_PULSE_WIDTH | PMOD_FREQUENCY | PMOD_PERIOD + * @return RQ Status Flags + */ +int CoreAPI::SetPulseInputMode(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, PMOD_DISABLED, PMOD_PERIOD)) + status = device.SetConfig(_PMOD, port, val); + return status; +} +/** + * Sets the Action on a Pulse (_PINA) see p.206 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Action: ENC_COMMAND | ENC_FEEDBACK | ENC_UNUSED + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseInputAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckMotor(mot) + && CheckRange(val, ENC_UNUSED, ENC_FEEDBACK)) + { + status = device.SetConfig(_PINA, port, mot + val); + } + return status; +} +/** + * Sets the Pulse Min Range (_PMIN) see p.207 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Minimum: 0 - 65000 us default: 1000 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseMin(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) && CheckRange(val, 0, 65000)) + { + status = device.SetConfig(_PMIN, port, val); + } + return status; +} +/** + * Sets the Pulse Max Range (_PMAX) see p.206 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Minimum: 0 - 65000 us default: 2000 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseMax(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) && CheckRange(val, 0, 65000)) + { + status = device.SetConfig(_PMAX, port, val); + } + return status; +} +/** + * Sets the Pulse Min Range (_PMIN) see p.205 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Minimum: 0 - 65000 us default: 1500 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseCenter(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) && CheckRange(val, 0, 65000)) + { + status = device.SetConfig(_PCTR, port, val); + } + return status; +} +/** + * Gets the Pulse Input Deadband (_PDB) see p. 205 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Deadband: 0 - 50 default: 0 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseDeadbeand(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) && CheckRange(val, 0, 50)) + { + status = device.SetConfig(_PDB, port, val); + } + return status; +} +/** + * Gets the Action on Max Pulse (_PMAX) see p.207 + * @param port Port: 0 - Max_ANALOG_INPUTS + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseMaxAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE) + && CheckMotor(mot)) + { + status = device.SetConfig(_PMAXA, port, val + mot); + } + return status; +} +/** + * Gets the Action on Min Pulse (_PMAX) see p.207 + * @param port Port: 0 - Max_ANALOG_INPUTS + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @return RQ Status Flags + */ +int CoreAPI::SetPulseMinAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE) + && CheckMotor(mot)) + { + status = device.SetConfig(_PMINA, port, val + mot); + } + return status; +} +/** + * Sets the Linearity on the Pulse Input (_PLIN) see p.206 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Linearty: LIN_LINEAR | LIN_EXP_WEAK | LIN_EXP_MEDIUM | LIN_EXP_STRONG | LIN_LOG_WEAK | LIN_LOG_MEDIUM | LIN_LOG_STRONG + * @return RQ Status Flags + */ +int CoreAPI::SetPulseLinearity(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) + && CheckRange(val, LIN_LINEAR, LIN_LOG_STRONG)) + { + status = device.SetConfig(_PLIN, port, val); + } + return status; +} +/** + * Sets the Digital Output Active Levels (_DOL) see p.200 + * @param port Port: 0 - MAX_DIGITAL_OUTPUTS + * @param val Active Level: DOL_ACTIVE_HIGH | DOL_ACTIVE_LOW + * @return RQ Status Flags + */ +int CoreAPI::SetDigitalOutputActiveLevel(int port, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS) + && CheckRange(val, DOL_ACTIVE_LOW, DOL_ACTIVE_HIGH)) + { + status = device.SetConfig(_DOL, port, val); + } + return status; +} +/** + * Sets the Digital Output Action (_DOA) see p.200 + * @param port Port: 0 - MAX_DIGITAL_OUTPUTS + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val Actions: DOA_NO_ACTION | DOA_MOTOR_ON | DOA_OVERVOLTAGE | DOA_OVERTEMPERATURE | DOA_MIRROR_STATUS_LED | DOA_NO_MOSFET_FAILURE + * @return RQ Status Flags + */ +int CoreAPI::SetDigitalOutputAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS) + && CheckRange(val, DOA_NO_ACTION, DOA_NO_MOSFET_FAILURE) + && CheckMotor(mot)) + { + status = device.SetConfig(_DOA, port, val + mot); + } + return status; +} +/** + * Gets the PWM Frequency (_PWMF) see p.215 + * @param val PWM Frequency multiplied with 10, Range: 10 - 200 (1 - 20kHz) + * @return RQ Status Flags + */ +int CoreAPI::SetPWMFrequency(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 10, 200)) + status = device.SetConfig(_PWMF, val); + return status; +} +/** + * Sets the Overvoltage Limit, at this point an overvoltage signal is issued (_OVL) see p.214 + * @param val Overvoltage Limit multiplied by 10: Range 100 - MAX_OVERVOLTAGE + * @return RQ Status Flags + */ +int CoreAPI::SetOvervoltageLimit(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 100, MAX_OVERVOLTAGE)) + status = device.SetConfig(_OVL, val); + return status; +} +/** + * Sets the Undervoltage Limit, This parameter sets the voltage below which the controller will turn off its power stage. (_UVL) see p.215 + * @param val Overvoltage Limit multiplied by 10: Range 50 - MAX_OVERVOLTAGE + * @return RQ Status Flags + */ +int CoreAPI::SetUndervoltageLimit(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 50, MAX_OVERVOLTAGE)) + status = device.SetConfig(_UVL, val); + return status; +} +/** + * Sets the Break Delay (_BKD) see p.214 + * @param val Delay in ms + * @return RQ Status Flags + */ +int CoreAPI::SetBrakeActivationDelay(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (val >= 0) + status = device.SetConfig(_BKD, val); + return status; +} +/** + * Sets the Short Circuit Detection Sensitivity (_THLD) see p.215 + * @param val Sensitivity: THLD_HIGH_SENSITIVITY | THLD_MEDIUM_SENSITIVITY | THLD_LOW_SENSITIVITY | THLD_DISABLED + * @return RQ Status Flags + */ +int CoreAPI::SetShortCircuitThreshold(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, THLD_HIGH_SENSITIVITY, THLD_DISABLED)) + status = device.SetConfig(_THLD, val); + return status; +} +/** + * Gets the Number of Poles of the BL Motor (_BPOL) see p.213 + * @param mot Motor: 1 or 2 + * @param val [description] + * @return [description] + */ +int CoreAPI::SetNumPoles(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.SetConfig(_BPOL, mot, val); + return status; +} +/** + * Sets the selected Encoder (_BLFB) see p.212 + * @param mot Motor: 1 or 2 + * @param val Feedback: BLFB_HALL_SENSOR | BLFB_ENCODER + * @return RQ Status Flags + */ +int CoreAPI::SetBrushlessFeedback(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2) && CheckRange(val, BLFB_HALL_SENSOR, BLFB_ENCODER)) + { + status = device.SetConfig(_BLFB, mot, val); + } + return status; +} +/** + * Set the Stall Detection Mode (_BLSTD) see p.213 + * @param mot Motor: 0 or 1 + * @param val Detection Modes: BLSTD_DISABLED | BLSTD_250MS_OVER_10 | BLSTD_500OMS_0VER_25 | BLSTD_1000MS_OVER_50 3 + * @return RQ Status Flags + */ +int CoreAPI::SetBrushlessStallDetection(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2) && CheckRange(val, BLSTD_DISABLED, BLSTD_1000MS_OVER_50)) + status = device.SetConfig(_BLSTD, mot, val); + return status; +} +/** + * (_BLL) see p.212 + * @param mot Motor: 1 or 2 + * @param val Counter: default -2000 + * @return RQ Status Flags + */ +int CoreAPI::SetEncoderLowLimit(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.SetConfig(_BLL, mot, val); + return status; +} +/** + * Encoder High Limit Action (_BHLA) see p.211 + * @param port Port: 1 or 2 + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::SetEncoderHighLimitAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) + && CheckMotor(mot) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE)) + status = device.SetConfig(_BHLA, port, mot + val); + return status; +} +/** + * Encoder Low Limit Action (_BHLA) see p.211 + * @param port Port: 1 or 2 + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::SetEncoderLowLimitAction(int port, int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) + && CheckMotor(mot) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE)) + status = device.SetConfig(_BLLA, port, val + mot); + return status; +} +/** + * Amps Limit (_ALIM) see p.216 + * @param val Amps multiplied with 10: 10A to Datasheet Max, default: 75% of Max + * @return RQ Status Flags + */ +int CoreAPI::SetMotorAmpsLimit(int val) +{ + return device.SetConfig(_ALIM, val); +} +/** + * Amps Trigger Value (_ATRIG) see p.217 + * @param val Amps multiplied with 10: 10A to Datasheet Max, default: 75% of Max + * @return RQ Status Flags + */ +int CoreAPI::SetMotorAmpsTriggerValue(int val) +{ + return device.SetConfig(_ATRIG, val); +} +/** + * Amps Trigger Action (_ATGA) see p.217 + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::SetMotorAmpsTriggerAction(int mot, int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckMotor(mot) + && CheckRange(val, DINA_NO_ACTION, DINA_LOAD_HOME_VALUE)) + status = device.SetConfig(_ATGA, val + mot); + return status; +} +/** + * Amps Trigger Delay (_ATGD) see p.217 + * @param val Delay in ms + * @return RQ Status Delay + */ +int CoreAPI::SetMotorAmpsTriggerDelay(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (val > 0) + status = device.SetConfig(_ATGD, val); + return status; +} +/** + * Max Power Forward (_MXPF) see p.220 + * @param val Power: 25 - 100, default: 100 + * @return RQ Status Flags + */ +int CoreAPI::SetMotorMaxPowerForward(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 25, 100)) + status = device.SetConfig(_MXPF, val); + return status; +} +/** + * Max Power Forward (_MXPR) see p.221 + * @param val Power: 25 - 100, default: 100 + * @return RQ Status Flags + */ +int CoreAPI::SetMotorMaxPowerReverse(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 25, 100)) + status = device.SetConfig(_MXPR, val); + return status; +} +/** + * Max RPM (_MXRPM) see p.221 + * @param val RPM: 10 - 65000, default: 3000 + * @return RQ Status Flags + */ +int CoreAPI::SetMotorMaxRPM(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 25, 65000)) + status = device.SetConfig(_MXRPM, val); + return status; +} +/** + * Gets the Motor Operating Mode (_MMOD) see p.220 + * @param val Mode: MMOD_OPEN_LOOP_SPEED | MMOD_CLOSED_LOOP_SPEED | MMOD_CLOSED_LOOP_POSITION_RELATIVE + * | MMOD_closed_LOPP_COUNT_POSITION | MMOD_CLOSED_LOOP_POSITION_TRACKING | MMOD_TORQUE + * @return RQ Status Flags + */ +int CoreAPI::SetMotorOperatingMode(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, MMOD_OPEN_LOOP_SPEED, MMOD_TORQUE)) + status = device.SetConfig(_MMOD, val); + return status; +} +/** + * Gets the Velocity value in RPM (_MVEL) see p.220 !! Use !S in operating Mode !! + * @param val Velocity + * @return RQ Status Flags + */ +int CoreAPI::SetMotorDefaultVelocity(int val) +{ + return device.SetConfig(_MVEL, val); +} +/** + * Gets the Turns between Limits (_MXTRN) see p.221 + * @param val Turns multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::SetMotorMaxTurns(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (val > 0) + status = device.SetConfig(_MXTRN, val * 10); + return status; +} +/** + * Gets the Proportional Gain for the Channel (_KP) see p.219 + * @param val Gain multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::SetProportionalGain(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (val > 0) + status = device.SetConfig(_KP, val * 10); + return status; +} +/** + * Gets the PID Integral Gain (_KI) see p.219 + * @param val Gain multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::SetIntegrationalGain(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (val > 0) + status = device.SetConfig(_KI, val * 10); + return status; +} +/** + * Gets the PID Differential Gain (_KD) see p.218 + * @param val Gain multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::SetDifferentialGain(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (val > 0) + status = device.SetConfig(_KD, val * 10); + return status; +} +/** + * Gets the PID Integral Cap (_ICAP) see p. 218 + * @param val Integral cap in %: 1 - 100, default: 100 + * @return RQ Status Flags + */ +int CoreAPI::SetMotorIntCap(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, 1, 100)) + status = device.SetConfig(_ICAP, val); + return status; +} +/** + * Gets the Loop Error Detection Mode (_CLERD) see p.218 + * @param val Detections Modes: CLERD_DISABLED | CLERD_250msGreater100 | CLERD_500msGreater250 | CLERD_1000msGreater500 + * @return RQ Status Flags + */ +int CoreAPI::SetLoopErrorMode(int val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(val, CLERD_DISABLED, CLERD_1000msGreater500)) + status = device.SetConfig(_CLERD, val); + return status; +} + +/**************************************************************/ +/************************ GETTER ******************************/ +/**************************************************************/ +/**************************************************************/ +/*********************** RUNTIME ******************************/ +/**************************************************************/ +/** + * \test +* Gets the Motorpower (_MOTPWR / _P) +* @param result Returns the actual Motorpower (Range 0 - 1000) +* @return RQ Status Flags +*/ +int CoreAPI::GetMotorPower(int &result) +{ + int status = device.GetValue(_MOTPWR, result); + return status; +} +/** + * \test +* Gets the Motor amps (_MOTAMPS / _A) +* @param amps Returns the Motoramps +* @return RQ Status Flags +*/ +int CoreAPI::GetMotorAmps(int &s) +{ + int status = device.GetValue(_MOTAMPS, amps); + return status; +} +/** + * \test +* Gets the Loop Error Count (_LPERR / _E) +* @param err Returns the number of Errors +* @return RQ Status Flags +*/ +int CoreAPI::GetLoopError(int &err) +{ + int status = device.GetValue(_LPERR, err); + return status; +} +/** + * \test +* Gets the Motor RPM (_BLSPEED / _BS) +* @param rpm Returns the current RPM +* @return RQ Status Flags +*/ +int CoreAPI::GetMotorRPM(int &rpm) +{ + int status = device.GetValue(_BLSPEED, rpm); + return status; + +} +/** + * \test +* Gets the Controller Voltage (_VOLTS 0) +* @param volt Returns the Controller Volt ( 126 => 12.6V) +* @return RQ Status Flags +*/ +int CoreAPI::GetControllerVolt(int &volt) +{ + int status = device.GetValue(_VOLTS, 0, volt); + return status; +} +/** + * \test +* Gets the 5V Output (_VOLTS 2) +* @param volt Returns the Controller Volt ( 5023 => 5.023V) +* @return RQ Status Flags +*/ +int CoreAPI::Get5VOutput(int &volt) +{ + int status = device.GetValue(_VOLTS, 2, volt); + return status; +} +/** + * \test +* Gets the Battery Voltage (_VOLTS 1) +* @param volt Returns the Controller Volt ( 120 => 12.0V) +* @return RQ Status Flags +*/ +int CoreAPI::GetBatteryVolt(int &volt) +{ + int status = device.GetValue(_VOLTS, 1, volt); + return status; +} +/** + * \test +* FGets the Motor Temperature (_Temp 1) +* @param temp Returns the Temperature in Celsius +* @return RQ Status Flags +*/ +int CoreAPI::GetMotorTemperature(int &temp) +{ + int status = device.GetValue(_TEMP, 1, temp); + return status; +} +/** + * \test +* Gets the Controller Temperature (_TEMP 2) +* @param temp Returns the Temperature in Celsius +* @return RQ Status Flags +*/ +int CoreAPI::GetMCUTemperature(int &temp) +{ + int status = device.GetValue(_TEMP, 2, temp); + return status; +} +/** + * \test + * (_P) see p.184 + * @param port Port + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetAbsoluteDesiredPosition(int port, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.GetValue(_P, port, value); + return status; +} +/** + * \test + * (_S) see p.185 + * @param port Port + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetMotorPositionVelocity(int port, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.GetValue(_S, port, value); + return status; +} +/** + * \test + * (_C) see p.176 + * @param port Port + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetEncoderCounter(int port, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.GetValue(_C, value); + return status; +} +/** + * \test + * (_CB) see p.176 + * @param port Port + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetBrushlessCounter(int port, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2)) + status = device.GetValue(_CB, port, value); + return status; +} +/** + * \test + * Gets a User Integer Variable (_VAR) see p.187 + * @param num Which One + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetUserIntegerVariables(int num, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(num, 0, 16)) + status = device.GetValue(_VAR, num, value); + return status; +} +/** + * \test + * Gets a User Bool Variable (_B) see p.174 + * @param num Which One + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetUserIntegerBool(int num, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(num, 0, 32)) + status = device.GetValue(_B, num, value); + return status; +} +/** + * \test + * Gets whether a Digital Out is on or off (_DO) see p. + * @param port Port + * @param value Return Value + * @return RQ Status Flags + */ +int CoreAPI::GetDigitalOuts(int port, int &value) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS)) + status = device.GetValue(_DO, port, value); + return status; +} +/**************************************************************/ +/************************ CONFIG ******************************/ +/**************************************************************/ + +/** +* Gets the MotorController Type (_TRN) see p.186 +* @param type Returns the Motorcontroler type +* @return RQ Status Flags +*/ +int CoreAPI::GetMotorControllerType(std::string &type) +{ + std::string response; + int status = device.GetRawValue(_TRN, response); + std::istringstream iss(response); + iss.ignore(256, ':'); + iss >> type; + return status; +} +/** +* Gets the Firmwareversion (_FID) see p.180 +* @param firmware Returns the Motorcontroler Firmware Version +* @return RQ Status Flags +*/ +int CoreAPI::GetMotorControllerFirmware(std::string &firmware) +{ + return device.GetRawValue(_FID, firmware); +} +/** +* Gets the Scripting Autostart Mode (_BRUN) see p.196 +* @param val BRUN_DISABLED | BRUN_DELAYED | BRUN_ACTIVATED +* @return RQ Status Flags +*/ +int CoreAPI::GetScriptingAutostart(int &val) +{ + return device.GetConfig(_BRUN, val); +} +/** +* Gets the AnalogCenterSafety (_ACS) see p. 196 +* @param val is Analog Safety enabled +* @return RQ Status Flags +*/ +int CoreAPI::GetAnalogCenterSafety(int &val) +{ + return device.GetConfig(_ACS, val);; +} +/** +* Gets the Telemetry String (_TELS) p.199 +* @param str Telemetry String +* @return RQ Status Flags +*/ +int CoreAPI::GetTelemetryString(std::string &str) +{ + return device.GetRawConfig(_TELS, str); +} +/** +* Gets the ChannelPriorities (_CPRI) p.197 +* @param port Port: 1 - 3 +* @param val The Array represents the priority (first to third), the content is CP_X +* @return RQ Status Flags +*/ +int CoreAPI::GetChannelPriorities(int port, int &val) +{ + int status; + if (CheckRange(port, 0, 3)) + status = device.GetConfig(_CPRI, port, val); + return status; +} +/** +* Gets the Serial Timout (_RWD) see p. 198 +* @param val Returns the Serial Timeout +* @return RQ Status Flags +*/ +int CoreAPI::GetSerialTimeout(int &val) +{ + return device.GetConfig(_RWD, val); +} +/** +* Gets the Linearity (_CLIN) see p.197 +* @param val Return the Linearity Values ( LIN_X) +* @return RQ Status Flags +*/ +int CoreAPI::GetLinearity(int &val) +{ + return device.GetConfig(_CLIN, val); +} +/** +* Gets Analog within Min & Max Safety (_AMS) see p.196 +* @param val Is Analog Safety enabled +* @return RQ Status Flags +*/ +int CoreAPI::GetAnalogMinMaxSafety(int &val) +{ + return device.GetConfig(_AMS, val);; +} +/** +* Read Brushless Count Relative (_CBR) see p.177 +* @param val Return Value +* @return [description] +*/ +int CoreAPI::GetBrushlessCountRelative(int &val) +{ + return device.GetConfig(_CBR, val); +} +/** +* Gets the Encoder Mode (_EMOD) see p.210 +* @param mot Select the Motor: MOT1 | MOT2 +* @param val Returns the USAGE: ENC_UNUSED | ENC_COMMAND | ENC_FEEDBACK +* @return RQ Status Flags +*/ +int CoreAPI::GetEncoderMode(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckMotor(mot)) + { + status = device.GetConfig(_EMOD, val); + ExtractDINA(mot, val); + } + return status; +} +/** +* Gets the Encoder PPR Value (_EPPR) see p.210 +* @param val Return Value, Range 1 - 5000 default: 100 +* @return RQ Status Flags +*/ +int CoreAPI::GetEncoderPPR(int &val) +{ + return device.GetConfig(_EPPR, val); +} +/** +* Gets the Encoder Low Count Limit (_ELL) see p.209 +* @param val Returns the Low Limit Count +* @return RQ Status Flags +*/ +int CoreAPI::GetEncoderLowLimitCount(int &val) +{ + return device.GetConfig(_ELL, val); +} +/** +* Gets the Encoder High Count Limit (_ELL) see p.208 +* @param val Returns the Low Limit Count +* @return RQ Status Flags +*/ +int CoreAPI::GetEncoderHighLimitCount(int &val) +{ + return device.GetConfig(_EHL, val); +} +/** +* Gets the Encoder Counter Load at Home Position (_EHOME) see p.209 +* @param val Returns +* @return RQ Status Flags +*/ +int CoreAPI::GetEncoderCounterLoadAtHomePosition(int &val) +{ + return device.GetConfig(_EHOME, val); +} +/** +* Gets the Encoder Low Limit Action (_EHLA) see p.209 +* @param mot Motor: MOT1 | MOT2 +* @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE +* @return RQ_Status_Flags +*/ +int CoreAPI::GetEncoderLowLimitAction(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckMotor(mot)) + { + status = device.GetConfig(_ELLA, val); + ExtractDINA(mot, val); + } + return status; +} +/** +* Gets the Encoder High Limit Action (_EHLA) see p.209 +* @param mot Motor: MOT1 | MOT2 +* @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE +* @return RQ_Status_Flags +*/ +int CoreAPI::GetEncoderHighLimitAction(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckMotor(mot)) + { + status = device.GetConfig(_EHLA, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Gets the Digital Input Active Level for each port (_DINL) see p.200 + * @param port Which port + * @param val High or Low + * @return RQ Status Flags + */ +int CoreAPI::GetDigitalInput(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_INPUTS)) + status = device.GetConfig(_DINL, port, val); + return status; +} +/** + * Gets the Digital Input Action if a port is triggered (_DINA) see p.199 + * @param port Port: 0 - MAX_DIGITAL_INPUTS + * @param mot Motor: DINA_MOT1 | DINA_MOT2 | DINA_MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::GetDigitalInputAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if ((mot == DINA_MOT1 || mot == DINA_MOT2 || mot == DINA_MOT12) + && CheckRange(port, 0, MAX_DIGITAL_INPUTS)) + { + status = device.GetConfig(_DINA, port, val); + if ((val & mot) != 0) + val = val & ~DINA_MOT12; + } + return status; +} +/** + * Gets the Analog Input Mode (_AMOD) see p.204 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val AMOD Values: AMOD_DISABLED | AMOD_ABSOLUTE | AMOD_RELATIVE + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogInputMode(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_AMOD, port, val); + return status; +} +/** + * Gets the Analog Input Actions for each port (_AINA) see p.202 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Returns the USAGE: ENC_UNUSED | ENC_COMMAND | ENC_FEEDBACK + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogInputAction(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_AINA, port, val); + return status; +} +/** + * Get Analog Input Range for each Point (_AMIN) see p. 203 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Min: 0 - 5000 mV default: 100mV + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogInputMin(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_AMIN, port, val); + return status; +} +/** + * Gets the Analog Input Center (_ACTR) see p. 201 + * @param port Port: 0 - MAX_ANALOG_INPUT + * @param val Center: 0 - 5000 default: 2500 + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogInputCenter(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_ACTR, port, val); + return status; +} +/** + * Gets the Analog Input Max (_AMAX) see p. 203 + * @param port Port: 0 - MAX_ANALOG_INPUT + * @param val Max: 0 - 5000 default: 4900 + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogInputMax(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_AMAX, port, val); + return status; +} +/** + * Gets the Analog Input Polarity for every port (_APOL) see p.204 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Polarity: POL_UNINVERTED | POL_INVERTED + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogInputPolarity(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_APOL, port, val); + return status; +} +/** + * Gets the Analog Deadband (_ADB) see p.201 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Deadband: 0 - 50 + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogDeadband(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_ADB, port, val); + return status; +} +/** + * Gets the Action on Analog Min (_AMINA) see p.201 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogMinAction(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_AMINA, port, val); + return status; +} +/** + * Gets the Action on Analog Max (_AMAXA + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::GetAnalogMaxAction(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_AMAXA, port, val); + return status; +} +/** + * Gets the Pulse Operating Mode (_PMOD) see p. 207 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val PM Values: PM_DISABLED | PM_PULSE_WIDTH | PM_FREQUENCY | PM_PERIOD + * @return RQ Status Flags + */ +int CoreAPI::GetPulseInputMode(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_PMOD, port, val); + return status; +} +/** + * Gets the Action on a Pulse (_PINA) see p.206 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Action: ENC_COMMAND | ENC_FEEDBACK | ENC_UNUSED + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseInputAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS) && CheckMotor(mot)) + status = device.GetConfig(_PINA, port, val); + ExtractDINA(mot, val); + return status; +} +/** + * Gets the Pulse Min Range (_PMIN) see p.207 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Minimum: 0 - 65000 us default: 1000 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseMin(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_PMIN, port, val); + return status; +} +/** + * Gets the Pulse Max Range (_PMAX) see p.206 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Minimum: 0 - 65000 us default: 2000 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseMax(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_PMAX, port, val); + return status; +} +/** + * Gets the Pulse Center Range (_PCTR) see p.205 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Minimum: 0 - 65000 us default: 1500 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseCenter(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_PCTR, port, val); + return status; +} +/** + * Gets the Pulse Input Deadband (_PDB) see p. 205 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Deadband: 0 - 50 default: 0 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseDeadbeand(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_PDB, port, val); + return status; +} +/** + * Gets the Action on Max Pulse (_PMAX) see p.207 + * @param port Port: 0 - Max_ANALOG_INPUTS + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseMaxAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + { + status = device.GetConfig(_PMAXA, port, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Gets the Action on Min Pulse (_PMAX) see p.207 + * @param port Port: 0 - Max_ANALOG_INPUTS + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @return RQ Status Flags + */ +int CoreAPI::GetPulseMinAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + { + status = device.GetConfig(_PMINA, port, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Gets the Linearity on the Pulse Input (_PLIN) see p.206 + * @param port Port: 0 - MAX_ANALOG_INPUTS + * @param val Linearty: LIN_LINEAR | LIN_EXP_WEAK | LIN_EXP_MEDIUM | LIN_EXP_STRONG | LIN_LOG_WEAK | LIN_LOG_MEDIUM | LIN_LOG_STRONG + * @return RQ Status Flags + */ +int CoreAPI::GetPulseLinearity(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_ANALOG_INPUTS)) + status = device.GetConfig(_PLIN, port, val); + return status; +} +/** + * Gets the Digital Output Active Levels (_DOL) see p.200 + * @param port Port: 0 - MAX_DIGITAL_OUTPUTS + * @param val Active Level: DO_ACTIVE_HIGH | DO_ACTIVE_LOW + * @return RQ Status Flags + */ +int CoreAPI::GetDigitalOutputActiveLevel(int port, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS)) + status = device.GetConfig(_DOL, port, val); + return status; +} +/** + * Gets the Digital Output Action (_DOA) see p.200 + * @param port Port: 0 - MAX_DIGITAL_OUTPUTS + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val Actions: DO_NO_ACTION | DO_MOTOR_ON | DO_OVERVOLTAGE | DO_OVERTEMPERATURE | DO_MIRROR_STATUS_LED | DO_NO_MOSFET_FAILURE + * @return RQ Status Flags + */ +int CoreAPI::GetDigitalOutputAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, MAX_DIGITAL_OUTPUTS) && CheckMotor(mot)) + { + status = device.GetConfig(_DOA, port, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Gets the PWM Frequency (_PWMF) see p.215 + * @param val PWM Frequency multiplied with 10, Range: 10 - 200 (1 - 20kHz) + * @return RQ Status Flags + */ +int CoreAPI::GetPWMFrequency(int &val) +{ + return device.GetConfig(_PWMF, val); +} +/** + * Gets the Overvoltage Limit, at this point an overvoltage signal is issued (_OVL) + * @param val Overvoltage Limit multiplied by 10: Range 100 - MAX_OVERVOLTAGE + * @return RQ Status Flags + */ +int CoreAPI::GetOvervoltageLimit(int &val) +{ + return device.GetConfig(_OVL, val); +} +/** + * Gets the Undervoltage Limit (_UVL) see p.215 + * @param val Overvoltage Limit multiplied by 10: Range 50 - MAX_OVERVOLTAGE + * @return RQ Status Flags + */ +int CoreAPI::GetUndervoltageLimit(int &val) +{ + return device.GetConfig(_UVL, val); +} +/** + * Gets the Break Delay (_BKD) see p. 214 + * @param val Delay in ms + * @return RQ Status Flags + */ +int CoreAPI::GetBrakeActivationDelay(int &val) +{ + return device.GetConfig(_BKD, val); +} +/** + * Gets the Short Circuit Detection Sensitivity (_THLD) see p.215 + * @param val Sensitivity: THLD_HIGH_SENSITIVITY | THLD_MEDIUM_SENSITIVITY | THLD_LOW_SENSITIVITY | THLD_DISABLED + * @return RQ Status Flags + */ +int CoreAPI::GetShortCircuitThreshold(int &val) +{ + return device.GetConfig(_THLD, val); +} + +/** + * Gets the Number of Poles of the BL Motor (_BPOL) see p.213 + * @param mot Motor: 1 or 2 + * @param val [description] + * @return [description] + */ +int CoreAPI::GetNumPoles(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.GetConfig(_BPOL, mot, val); + return status; +} +/** + * Gets the selected Encoder (_BLFB) see p.212 + * @param mot Motor: 1 or 2 + * @param val Feedback: BLFB_HALL_SENSOR | BLFB_ENCODER + * @return RQ Status Flags + */ +int CoreAPI::GetBrushlessFeedback(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.GetConfig(_BLFB, mot, val); + return status; +} + +/** + * Get the Stall Detection Mode (_BLSTD) see p.213 + * @param mot Motor: 1 or 2 + * @param val Detection Modes: BLSTD_DISABLED | BLSTD_250MS_OVER_10 | BLSTD_500OMS_0VER_25 | BLSTD_1000MS_OVER_50 3 + * @return RQ Status Flags + */ +int CoreAPI::GetBrushlessStallDetection(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.GetConfig(_BLSTD, mot, val); + return status; +} +/** + * (_BLL) see p.212 + * @param mot Motor: 1 or 2 + * @param val Counter: default -2000 + * @return RQ Status Flags + */ +int CoreAPI::GetEncoderLowLimit(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.GetConfig(_BLL, mot, val); + return status; +} +/** + * Gets the Brushless Counter High Limit (_BHL) see p.211 + * @param mot Motor: 1 or 2 + * @param val Counter default -2000 + * @return RQ Status Flags + */ +int CoreAPI::GetEncoderHighLimit(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.GetConfig(_BHL, mot, val); + return status; +} +/** + * Brushless Counter Load at Home Position (_BHOME) see p.211 + * @param mot Motor: 1 or 2 + * @param val Counter + * @return RQ Status Flags + */ +int CoreAPI::GetBrushlessHomeCounter(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(mot, 0, 2)) + status = device.GetConfig(_BHOME, mot, val); + return status; +} +/** + * Encoder High Limit Action (_BHLA) see p.211 + * @param port Port: 1 or 2 + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::GetEncoderHighLimitAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) && CheckMotor(mot)) + { + status = device.GetConfig(_BHLA, port, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Encoder Low Limit Action (_BHLA) see p.211 + * @param port Port: 1 or 2 + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::GetEncoderLowLimitAction(int port, int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckRange(port, 0, 2) && CheckMotor(mot)) + { + status = device.GetConfig(_BLLA, port, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Amps Limit (_ALIM) see p.216 + * @param val Amps multiplied with 10: 10A to Datasheet Max, default: 75% of Max + * @return RQ Status Flags + */ +int CoreAPI::GetMotorAmpsLimit(int &val) +{ + return device.GetConfig(_ALIM, val); +} +/** + * Amps Trigger Value (_ATRIG) see p.217 + * @param val Amps multiplied with 10: 10A to Datasheet Max, default: 75% of Max + * @return RQ Status Flags + */ +int CoreAPI::GetMotorAmpsTriggerValue(int &val) +{ + return device.GetConfig(_ATRIG, val); +} +/** + * Amps Trigger Action (_ATGA) see p.217 + * @param mot Motor: MOT1 | MOT2 | MOT12 + * @param val DINA Values: DINA_NO_ACTION | DINA_SAFETY_STOP | DINA_EMERGENCY_STOP | DINA_MOTOR_STOP | DINA_FORWARD_LIMIT_SWITCH | + DINA_REVERSE_LIMIT_SWITCH | DINA_INVERT_DIRECTION | DINA_RUN_MICROBASIC | DINA_LOAD_HOME_VALUE + * @return RQ Status Flags + */ +int CoreAPI::GetMotorAmpsTriggerAction(int mot, int &val) +{ + int status = RQ_INVALID_CONFIG_ITEM; + if (CheckMotor(mot)) + { + status = device.GetConfig(_ATGA, val); + ExtractDINA(mot, val); + } + return status; +} +/** + * Amps Trigger Delay (_ATGD) see p.217 + * @param val Delay in ms + * @return RQ Status Delay + */ +int CoreAPI::GetMotorAmpsTriggerDelay(int &val) +{ + return device.GetConfig(_ATGD, val); +} +/** + * Max Power Forward (_MXPF) see p.220 + * @param val Power: 25 - 100, default: 100 + * @return RQ Status Flags + */ +int CoreAPI::GetMotorMaxPowerForward(int &val) +{ + return device.GetConfig(_MXPF, val); +} +/** + * Max Power Forward (_MXPR) see p.221 + * @param val Power: 25 - 100, default: 100 + * @return RQ Status Flags + */ +int CoreAPI::GetMotorMaxPowerReverse(int &val) +{ + return device.GetConfig(_MXPR, val); +} +/** + * Max RPM (_MXRPM) see p.221 + * @param val RPM: 10 - 65000, default: 3000 + * @return RQ Status Flags + */ +int CoreAPI::GetMotorMaxRPM(int &val) +{ + return device.GetConfig(_MXRPM, val); +} +/** + * Get Acceleration time in 0.1 RPM per seconds (_MAC) see p.219 + * @param val Accel: 100 to 32000 + * @return RQ Status Flags + */ +int CoreAPI::GetAcceleration(int &val) +{ + return device.GetConfig(_MAC, val); +} +/** + * Gets Deceleration time in 0.1 RPM per second (_MDEC) see p.220 + * @param val Deccel: 100 - 32000 + * @return RQ Status Flags + */ +int CoreAPI::GetDeacceleration(int &val) +{ + return device.GetConfig(_MDEC, val); +} +/** + * Gets the Motor Operating Mode (_MMOD) see p.220 + * @param val Mode: MMOD_OPEN_LOOP_SPEED | MMOD_CLOSED_LOOP_SPEED | MMOD_CLOSED_LOOP_POSITION_RELATIVE + * | MMOD_closed_LOPP_COUNT_POSITION | MMOD_CLOSED_LOOP_POSITION_TRACKING | MMOD_TORQUE + * @return RQ Status Flags + */ +int CoreAPI::GetMotorOperatingMode(int &val) +{ + return device.GetConfig(_MMOD, val); +} +/** + * Gets the Velocity value in RPM (_MVEL) see p.220 + * @param val Velocity + * @return RQ Status Flags + */ +int CoreAPI::GetMotorDefaultVelocity(int &val) +{ + return device.GetConfig(_MVEL, val); +} +/** + * Gets the Turns between Limits (_MXTRN) see p.221 + * @param val Turns multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::GetMotorMaxTurns(int &val) +{ + return device.GetConfig(_MXTRN, val); +} +/** + * Gets the Proportional Gain for the Channel (_KP) see p.219 + * @param val Gain multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::GetProportionalGain(int &val) +{ + return device.GetConfig(_KP, val); +} +/** + * Gets the PID Integral Gain (_KI) see p.219 + * @param val Gain multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::GetIntegrationalGain(int &val) +{ + return device.GetConfig(_KI, val); +} +/** + * Gets the PID Differential Gain (_KD) see p.218 + * @param val Gain multiplied with 10 + * @return RQ Status Flags + */ +int CoreAPI::GetDifferentialGain(int &val) +{ + return device.GetConfig(_KD, val); +} +/** + * Gets the PID Integral Cap (_ICAP) see p. 218 + * @param val Integral cap in %: 1 - 100, default: 100 + * @return RQ Status Flags + */ +int CoreAPI::GetMotorIntCap(int &val) +{ + return device.GetConfig(_ICAP, val); +} +/** + * Gets the Loop Error Detection Mode (_CLERD) see p.218 + * @param val Detections Modes: CLERD_DISABLED | CLERD_250msGreater100 | CLERD_500msGreater250 | CLERD_1000msGreater500 + * @return RQ Status Flags + */ +int CoreAPI::GetLoopErrorMode(int &val) +{ + return device.GetConfig(_CLERD, val); +} +/** + * Device Connected + * @return bool + */ +bool CoreAPI::IsConnected() +{ + return device.IsConnected(); +} +/**************************************************************/ +/************************ INLINE ******************************/ +/**************************************************************/ +bool inline CoreAPI::CheckRange(int val, int min, int max) +{ + return val >= min && val <= max; +} +bool inline CoreAPI::CheckMotor(int mot) +{ + return mot == MOT1 || mot == MOT2 || mot == MOT12; +} +void inline CoreAPI::ExtractDINA(int mot, int &val) +{ + if ((val & mot) != 0) + val = val & ~MOT12; +} diff --git a/src/lib/ecu_api/Mapping.cpp b/src/lib/ecu_api/Mapping.cpp new file mode 100644 index 0000000..06a5fe1 --- /dev/null +++ b/src/lib/ecu_api/Mapping.cpp @@ -0,0 +1,107 @@ +#include "Mapping.h" + +#include +#include +#include "Constants.h" + +using namespace std; + +static map ReadMappings_21; // Read +static map ReadMappings_64; // Read +static map WriteMappings_20; // Write + +Mapping::Mapping() +{ + ReadMappings_21[_A] = 0x0; + ReadMappings_21[_M] = 0x1; + ReadMappings_21[_P] = 0x2; + ReadMappings_21[_S] = 0x3; + ReadMappings_21[_C] = 0x4; + ReadMappings_21[_CB] = 0x5; + ReadMappings_21[_VAR] = 0x6; + ReadMappings_21[_SR] = 0x7; + ReadMappings_21[_CR] = 0x8; + ReadMappings_21[_CBR] = 0x9; + ReadMappings_21[_BS] = 0xA; + ReadMappings_21[_BSR] = 0xB; + ReadMappings_21[_BA] = 0xC; + ReadMappings_21[_V] = 0xD; + ReadMappings_21[_D] = 0xE; + ReadMappings_21[_T] = 0xF; + ReadMappings_21[_F] = 0x10; + ReadMappings_21[_FS] = 0x11; + ReadMappings_21[_FF] = 0x12; + ReadMappings_21[_DO] = 0x13; + ReadMappings_21[_E] = 0x14; + ReadMappings_21[_B] = 0x15; + ReadMappings_21[_CIS] = 0x16; + ReadMappings_21[_CIA] = 0x17; + ReadMappings_21[_CIP] = 0x18; + ReadMappings_21[_TM] = 0x19; + ReadMappings_21[_K] = 0x1A; + ReadMappings_21[_DR] = 0x1B; + ReadMappings_21[_MA] = 0x1C; + ReadMappings_21[_MGD] = 0x1D; + ReadMappings_21[_MGT] = 0x1E; + ReadMappings_21[_MGM] = 0x1F; + ReadMappings_21[_MGS] = 0x20; + // ReadMappings_21[_FM] = 0x20; + // **** + ReadMappings_64[_DI] = 0x00; + ReadMappings_64[_AI] = 0x01; + ReadMappings_64[_AIC] = 0x02; + ReadMappings_64[_PI] = 0x03; + ReadMappings_64[_PIC] = 0x04; + // **** + WriteMappings_20[_GO] = 0x00; + WriteMappings_20[_P] = 0x01; + WriteMappings_20[_S] = 0x02; + WriteMappings_20[_C] = 0x03; + WriteMappings_20[_CB] = 0x04; + WriteMappings_20[_VAR] = 0x05; + WriteMappings_20[_AC] = 0x06; + WriteMappings_20[_DC] = 0x07; + WriteMappings_20[_DS] = 0x08; + WriteMappings_20[_D1] = 0x09; + WriteMappings_20[_D0] = 0x0A; + WriteMappings_20[_H] = 0x0B; + WriteMappings_20[_EX] = 0x0C; + WriteMappings_20[_MG] = 0x0D; + WriteMappings_20[_MS] = 0x0E; + WriteMappings_20[_PR] = 0x0F; + WriteMappings_20[_PX] = 0x10; + WriteMappings_20[_PRX] = 0x11; + WriteMappings_20[_AX] = 0x12; + WriteMappings_20[_DX] = 0x13; + WriteMappings_20[_SX] = 0x14; + WriteMappings_20[_B] = 0x15; + WriteMappings_20[_EES] = 0x17; +} +Mapping::~Mapping() {} + +/** + * Maps the USB/COM Defines to the SDO Objects + * @param cmd USB/COM Define + * @return SDO Index + */ +__u8 Mapping::GetReadMapping(int cmd) +{ + __u8 mappedCmd = 0; + if (ReadMappings_21.find(cmd) != ReadMappings_21.end()) + mappedCmd = ReadMappings_21[cmd]; + else + mappedCmd = ReadMappings_64[(__u8)cmd]; + return mappedCmd; +} +/** + * Maps the USB/COM Defines to the SDO Objects + * @param cmd USB/COM Define + * @return SDO Index + */ +__u8 Mapping::GetWriteMapping(int cmd) +{ + __u8 mappedCmd = 0; + if (WriteMappings_20.find(cmd) != WriteMappings_20.end()) + mappedCmd = WriteMappings_20[cmd]; + return mappedCmd; +} diff --git a/src/lib/ecu_api/RoboteqDevice.cpp b/src/lib/ecu_api/RoboteqDevice.cpp new file mode 100644 index 0000000..8a34cae --- /dev/null +++ b/src/lib/ecu_api/RoboteqDevice.cpp @@ -0,0 +1,234 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ErrorCodes.h" +#include "RoboteqDevice.h" +#include + +using namespace std; + +RoboteqDevice::RoboteqDevice(int type) : com(type) +{} +RoboteqDevice::~RoboteqDevice() +{} +/** + * Checks if the Device is Connected (Only calling ComAPI) + * @return connected? + */ +bool RoboteqDevice::IsConnected() +{ + return true;//com.IsConnected(); +} +/** + * Send the rquested Command to the Controller + * @param configItem Determines which Command is issued + * @param index Determines which Value will be returned + * @param value Determines what value is issued + * @return RQ Status flags + */ +int RoboteqDevice::SetConfig(int configItem, int index, int value) +{ + string response; + if (configItem < 0 || configItem > 255) + return RQ_INVALID_CONFIG_ITEM; + + if (index < 0) + return RQ_INDEX_OUT_RANGE; + + int status = com.IssueCommand("^", configItem, index, to_string(value), response, true); + if (status != RQ_SUCCESS) + return status; + if (response != "+") + return RQ_SET_CONFIG_FAILED; + + return RQ_SUCCESS; +} +/** + * Calls the SetConfig(int, int, int) Method with index set to 1 + * @param configItem Determines which Command is issued + * @param value Determines what value is issued + * @return RQ Status Flags + */ +int RoboteqDevice::SetConfig(int configItem, int value) +{ + return SetConfig(configItem, 1, value); +} +/** + * !! USE ONLY IF YOU KNOW WHAT YOU ARE DOING !! Not supported ATM + * @param configItem Determines which Command is issued + * @param str args to pass + * @return RQ Status Flags + */ +int RoboteqDevice::SetRawConfig(int configItem, string str) +{ + string response; + + if (configItem < 0 || configItem > 255) + return RQ_INVALID_CONFIG_ITEM; + + int status = com.IssueCommand("^", configItem, 0, str, response, true); + if (status != RQ_SUCCESS) + return status; + if (response != "+") + return RQ_SET_CONFIG_FAILED; + + return RQ_SUCCESS; +} +/** + * Sends the requested command to the Controller + * @param commandItem Determines which Command is issued + * @param index Determines which Value will be returned + * @param value Determines what value is issued + * @return RQ Status flags + */ +int RoboteqDevice::SetCommand(int commandItem, int index, int value) +{ + string response; + + if (commandItem < 0 || commandItem > 255) + return RQ_INVALID_COMMAND_ITEM; + + if (index < 0) + return RQ_INDEX_OUT_RANGE; + string toString = to_string(value); + int status = com.IssueCommand("!", commandItem, index, toString , response, true); + //PDBG("status %s", status == RQ_SUCCESS ? "success" : "failed"); + //if (status != RQ_SUCCESS) { + // return status; + //if (response != "+") + // PERR("Set Command failed %d", status); + // return RQ_SET_COMMAND_FAILED; + //} + + return status; +} +/** + * Calls SetCommand(int, int, int) Method with index set to 1 + * @param commandItem Determines which Command is issued + * @param value The Value send to the Controller + * @return RQ Status Flags + */ +int RoboteqDevice::SetCommand(int commandItem, int value) +{ + return SetCommand(commandItem, 1, value); +} +/** + * Calls SetCommand(int, int, int) with index to 1 and value to 0 + * @param commandItem Determines which Command is issued + * @return RQ Status Flags + */ +int RoboteqDevice::SetCommand(int commandItem) +{ + return SetCommand(commandItem, 1, 0); +} +/** + * Sends the requested configItem to the Controller + * @param configItem Determines which Command is issued + * @param index Determines which Value will be returned + * @param result Value returned by the Controller + * @return RQ Status Flags + */ +int RoboteqDevice::GetConfig(int configItem, int index, int &result) +{ + string response; + + if (configItem < 0 || configItem > 255) + return RQ_INVALID_CONFIG_ITEM; + + if (index < 0) + return RQ_INDEX_OUT_RANGE; + + int status = com.IssueCommand("~", configItem, index, "", response); + if (status != RQ_SUCCESS) + return status; + + istringstream iss(response); + iss >> result; + + if (iss.fail()) + return RQ_GET_CONFIG_FAILED; + + return RQ_SUCCESS; +} +/** + * Calls the GetConfig(int, int, int&) Method with index set to 1 + * @param configItem Determines which Command is issued + * @param result Value returned by the Controller + * @return RQ Status Flags + */ +int RoboteqDevice::GetConfig(int configItem, int &result) +{ + return GetConfig(configItem, 1, result); +} +/** + * Calls the GetValue(int, int, int&) Method with index set to 1 + * @param operatingItem Determines which Command is issued + * @param result Value returned by the Controller + * @return RQ Status Flags + */ +int RoboteqDevice::GetValue(int operatingItem, int &result) +{ + return GetValue(operatingItem, 1, result); +} +/** + * Returns the Raw Output + * @param operatingItem Determines whicht Command is issued + * @param result Returns the string ( raw ) + * @return RQ Status Flags + */ +int RoboteqDevice::GetRawConfig(int operatingItem, std::string &result) +{ + if (operatingItem < 0 || operatingItem > 255) + return RQ_INVALID_OPER_ITEM; + + return com.IssueCommand("~", operatingItem, 0, "", result);; +} +/** + * The Response of the Controller is parsed and stored in the result array + * @param operatingItem Determines which Command is issued + * @param index Determines which Value will be returned + * @param result Value returned by the Controller + * @return RQ Status Flags + */ +int RoboteqDevice::GetValue(int operatingItem, int index, int &result) +{ + string response; + + if (operatingItem < 0 || operatingItem > 255) + return RQ_INVALID_OPER_ITEM; + + if (index < 0) + return RQ_INDEX_OUT_RANGE; + + + int status = com.IssueCommand("?", operatingItem, index, "", response); + if (status != RQ_SUCCESS) + return status; + + istringstream iss(response); + iss >> result; + + if (iss.fail()) + return RQ_GET_VALUE_FAILED; + + return RQ_SUCCESS; +} +/** + * Returns the Raw Output + * @param operatingItem Determines whicht Command is issued + * @param result Returns the string ( raw ) + * @return RQ Status Flags + */ +int RoboteqDevice::GetRawValue(int operatingItem, string &result) +{ + if (operatingItem < 0 || operatingItem > 255) + return RQ_INVALID_OPER_ITEM; + + return com.IssueCommand("?", operatingItem, 0, "", result);; +}