adding dependencies

This commit is contained in:
Janosch
2022-10-10 12:39:30 +01:00
parent 0e8e1e4db6
commit 2327ae7aab
867 changed files with 137599 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANAIO_H_INCLUDED
#define ANAIO_H_INCLUDED
#include <stdint.h>
#include "anain_prj.h"
class AnaIn
{
public:
AnaIn(int chan): firstValue(&values[chan]) {}
#define ANA_IN_ENTRY(name, port, pin) static AnaIn name;
ANA_IN_LIST
#undef ANA_IN_ENTRY
#define ANA_IN_ENTRY(name, port, pin) +1
static const int ANA_IN_COUNT = ANA_IN_LIST;
#undef ANA_IN_ENTRY
static void Start();
void Configure(uint32_t port, uint8_t pin);
uint16_t Get();
private:
static uint16_t values[];
static uint8_t channel_array[];
uint16_t GetIndex() { return firstValue - values; }
static uint8_t AdcChFromPort(uint32_t command_port, int command_bit);
static int median3(int a, int b, int c);
uint16_t* const firstValue;
};
//Configure all AnaIn objects from the given list
#define ANA_IN_ENTRY(name, port, pin) AnaIn::name.Configure(port, pin);
#define ANA_IN_CONFIGURE(l) l
#endif // ANAIO_H_INCLUDED
+70
View File
@@ -0,0 +1,70 @@
/*
* This file is part of the stm32-sine project.
*
* Copyright (C) 2021 David J. Fiddes <D.J@fiddes.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CRC8_H_
#define __CRC8_H_
#include <stdint.h>
/*
* Precalculated look up table for CRC calculation
*/
extern const uint8_t crc_table[256];
/**
* \brief Calculate 8-bit CRC
*
*
* Calculate an 8-bit CRC of a block of data. The algorithm used depends on
* library configuration.
*
* \param[in] p pointer to the data to take we wish to compute the CRC of
* \param[in] len length of the data
* \param[in] crc Initial value for the CRC algorithm (or CRC of previous data)
*
* \return Calculated CRC value
*/
inline uint8_t crc8(uint8_t* p, uint8_t len, uint8_t crc)
{
while (len--)
{
crc = crc_table[crc ^ *p++];
}
return crc;
}
/**
* \brief Calculate 8-bit CRC of a byte
*
* Calculate an 8-bit CRC of a single byte. The algorithm used depends on
* library configuration.
*
* \param[in] input data byte to compute the CRC of
* \param[in] crc Initial value for the CRC algorithm (or CRC of previous data)
*
* \return Calculated CRC value
*/
inline uint8_t crc8(uint8_t input, uint8_t crc)
{
crc = crc_table[crc ^ input];
return crc;
}
#endif /* __CRC8_H_ */
+41
View File
@@ -0,0 +1,41 @@
/*
* This file is part of the stm32-sine project.
*
* Copyright (C) 2021 David J. Fiddes <D.J@fiddes.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DELAY_H
#define DELAY_H
/**
* \brief Blocking delay for a period
*
* \param[in] period Length of the delay in micro-seconds
*/
inline void uDelay(int period)
{
// Empirically determined constant by measurement of GPIO toggle
// of 1000 uS delay on a 72MHz STM32F103 processor
static const int CyclesPerMicroSecond = 12;
int iterations = period * CyclesPerMicroSecond;
for (int i = 0; i < iterations; i++)
{
__asm__("nop");
}
}
#endif // DELAY_H
+89
View File
@@ -0,0 +1,89 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DIGIO_H_INCLUDED
#define DIGIO_H_INCLUDED
#include <libopencm3/stm32/gpio.h>
#include "digio_prj.h"
namespace PinMode {
enum PinMode
{
INPUT_PD,
INPUT_PU,
INPUT_FLT,
INPUT_AIN,
OUTPUT,
OUTPUT_OD,
LAST
};
}
class DigIo
{
public:
#define DIG_IO_ENTRY(name, port, pin, mode) static DigIo name;
DIG_IO_LIST
#undef DIG_IO_ENTRY
/** Map GPIO pin object to hardware pin.
* @param[in] port port to use for this pin
* @param[in] pin port-pin to use for this pin
* @param[in] mode pinmode to use
*/
void Configure(uint32_t port, uint16_t pin, PinMode::PinMode pinMode);
/**
* Get pin value
*
* @param[in] io pin index
* @return pin value
*/
bool Get() { return gpio_get(_port, _pin) > 0; }
/**
* Set pin high
*
* @param[in] io pin index
*/
void Set() { gpio_set(_port, _pin); }
/**
* Set pin low
*
* @param[in] io pin index
*/
void Clear() { gpio_clear(_port, _pin); }
/**
* Toggle pin
*
* @param[in] io pin index
*/
void Toggle() { gpio_toggle(_port, _pin); }
private:
uint32_t _port;
uint16_t _pin;
};
//Configure all digio objects from the given list
#define DIG_IO_ENTRY(name, port, pin, mode) DigIo::name.Configure(port, pin, mode);
#define DIG_IO_CONFIGURE(l) l
#endif // DIGIO_H_INCLUDED
+62
View File
@@ -0,0 +1,62 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ERRORMESSAGE_H
#define ERRORMESSAGE_H
#include "errormessage_prj.h"
#include <stdint.h>
#define ERROR_MESSAGE_ENTRY(id, type) ERR_##id,
typedef enum
{
ERROR_NONE,
ERROR_MESSAGE_LIST
ERROR_MESSAGE_LAST
} ERROR_MESSAGE_NUM;
#undef ERROR_MESSAGE_ENTRY
typedef enum
{
ERROR_STOP,
ERROR_DERATE,
ERROR_DISPLAY,
ERROR_LAST
} ERROR_TYPE;
class ErrorMessage
{
public:
static void SetTime(uint32_t time);
static void Post(ERROR_MESSAGE_NUM err);
static void UnpostAll();
static void PrintAllErrors();
static void PrintNewErrors();
static ERROR_MESSAGE_NUM GetLastError();
protected:
private:
static void PrintError(uint32_t time, ERROR_MESSAGE_NUM err);
static uint32_t timeTick;
static uint32_t currentBufIdx;
static uint32_t lastPrintIdx;
static bool posted[ERROR_MESSAGE_LAST];
static ERROR_MESSAGE_NUM lastError;
};
#endif // ERRORMESSAGE_H
+47
View File
@@ -0,0 +1,47 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FOC_H
#define FOC_H
#include <stdint.h>
#include "my_fp.h"
class FOC
{
public:
static void SetAngle(uint16_t angle);
static void ParkClarke(s32fp il1, s32fp il2);
static int32_t GetQLimit(int32_t maxVd);
static int32_t GetTotalVoltage(int32_t ud, int32_t uq);
static void InvParkClarke(int32_t ud, int32_t uq);
static void Mtpa(int32_t is, int32_t& idref, int32_t& iqref);
static int32_t GetMaximumModulationIndex();
static s32fp id;
static s32fp iq;
static int32_t DutyCycles[3];
protected:
private:
static uint32_t sqrt(uint32_t rad);
static u32fp fpsqrt(u32fp rad);
static s32fp sin;
static s32fp cos;
};
#endif // FOC_H
+43
View File
@@ -0,0 +1,43 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FU_H_INCLUDED
#define FU_H_INCLUDED
#include <stdint.h>
#include "my_fp.h"
class MotorVoltage
{
public:
static void SetBoost(uint32_t boost);
static void SetWeakeningFrq(float frq);
static void SetMaxAmp(uint32_t maxAmp);
static uint32_t GetAmp(u32fp frq);
static uint32_t GetAmpPerc(u32fp frq, u32fp perc);
private:
static void CalcFac();
static uint32_t boost;
static u32fp fac;
static uint32_t maxAmp;
static u32fp endFrq;
static u32fp maxFrq;
};
#endif // FU_H_INCLUDED
+56
View File
@@ -0,0 +1,56 @@
/*
* This file is part of the stm32-car project.
*
* Copyright (C) 2021 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LINBUS_H
#define LINBUS_H
class LinBus
{
public:
/** Default constructor */
LinBus(uint32_t usart, int baudrate);
void Request(uint8_t id, uint8_t* data, uint8_t len);
bool HasReceived(uint8_t pid, uint8_t requiredLen);
uint8_t* GetReceivedBytes() { return &recvBuffer[payloadIndex]; }
protected:
private:
struct HwInfo
{
uint32_t usart;
uint8_t dmatx;
uint8_t dmarx;
uint32_t port;
uint16_t pin;
};
static uint8_t Checksum(uint8_t pid, uint8_t* data, int len);
static uint8_t Parity(uint8_t id);
static const HwInfo hwInfo[];
static const int payloadIndex = 3;
static const int pidIndex = 2;
uint32_t usart;
const HwInfo* hw;
uint8_t sendBuffer[11];
uint8_t recvBuffer[12];
};
#endif // LINBUS_H
+65
View File
@@ -0,0 +1,65 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MY_FP_H_INCLUDED
#define MY_FP_H_INCLUDED
#include <stdint.h>
#define FRAC_DIGITS 5
#ifndef CST_DIGITS
#define CST_DIGITS FRAC_DIGITS
#endif
#define FRAC_FAC (1 << CST_DIGITS)
#define CST_CONVERT(a) ((a) << (CST_DIGITS - FRAC_DIGITS))
#define CST_ICONVERT(a) ((a) >> (CST_DIGITS - FRAC_DIGITS))
#define UTOA_FRACDEC 100
#define FP_DECIMALS 2
#define FP_TOFLOAT(a) (((float)a) / FRAC_FAC)
#define FP_FROMINT(a) ((s32fp)((a) << CST_DIGITS))
#define FP_TOINT(a) ((s32fp)((a) >> CST_DIGITS))
#define FP_FROMFLT(a) ((s32fp)((a) * FRAC_FAC))
#define FP_MUL(a, b) (((a) * (b)) >> CST_DIGITS)
#define FP_DIV(a, b) (((a) << CST_DIGITS) / (b))
typedef uint32_t u32fp;
typedef int32_t s32fp;
typedef int16_t s16fp;
typedef uint16_t u16fp;
#ifdef __cplusplus
extern "C"
{
#endif
char* fp_itoa(char * buf, s32fp a);
s32fp fp_atoi(const char *str, int fracDigits);
u32fp fp_sqrt(u32fp rad);
s32fp fp_ln(unsigned int x);
#ifdef __cplusplus
}
#endif
#endif
+33
View File
@@ -0,0 +1,33 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MY_MATH_H_INCLUDED
#define MY_MATH_H_INCLUDED
#define ABS(a) ((a) < 0?(-(a)) : (a))
#define MIN(a,b) ((a) < (b)?(a):(b))
#define MAX(a,b) ((a) > (b)?(a):(b))
#define RAMPUP(current, target, rate) ((target < current || (current + rate) > target) ? target : current + rate)
#define RAMPDOWN(current, target, rate) ((target > current || (current - rate) < target) ? target : current - rate)
#define IIRFILTER(l,n,c) (((n) + ((l) << (c)) - (l)) >> (c))
#define IIRFILTERF(l,n,c) (((n) + (l) * ((1 << (c)) - 1)) / (1 << (c)))
#define MEDIAN3(a,b,c) ((a) > (b) ? ((b) > (c) ? (b) : ((a) > (c) ? (c) : (a))) \
: ((a) > (c) ? (a) : ((b) > (c) ? (c) : (b))))
#define CHK_BIPOLAR_OFS(ofs) ((ofs < (2048 - 512)) || (ofs > (2048 + 512)))
#endif // MY_MATH_H_INCLUDED
+48
View File
@@ -0,0 +1,48 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MY_STRING_H
#define MY_STRING_H
#ifndef NULL
#define NULL 0L
#endif
#define TOSTR_(...) #__VA_ARGS__
#define STRINGIFY(x) TOSTR_(x)
#ifdef __cplusplus
extern "C"
{
#endif
int my_strcmp(const char *str1, const char *str2);
void my_strcat(char *str1, const char *str2);
int my_strlen(const char *str);
const char *my_strchr(const char *str, const char c);
int my_ltoa(char *buf, int val, int base);
int my_atoi(const char *str);
char *my_trim(char *str);
void memcpy32(int* target, int *source, int length);
void memset32(int* target, int value, int length);
void my_strcpy(char *str1, const char *str2);
#ifdef __cplusplus
}
#endif
#endif // MY_STRING_H
+34
View File
@@ -0,0 +1,34 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PARAM_SAVE_H_INCLUDED
#define PARAM_SAVE_H_INCLUDED
#ifdef __cplusplus
extern "C"
{
#endif
uint32_t parm_save(void);
int parm_load(void);
#ifdef __cplusplus
}
#endif
#endif // PARAM_SAVE_H_INCLUDED
+85
View File
@@ -0,0 +1,85 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PARAM_H_INCLUDED
#define PARAM_H_INCLUDED
#include "param_prj.h"
#include "my_fp.h"
namespace Param
{
#define PARAM_ENTRY(category, name, unit, min, max, def, id) name,
#define VALUE_ENTRY(name, unit, id) name,
typedef enum
{
PARAM_LIST
PARAM_LAST,
PARAM_INVALID
} PARAM_NUM;
#undef PARAM_ENTRY
#undef VALUE_ENTRY
typedef enum
{
TYPE_PARAM,
TYPE_VALUE,
TYPE_LAST
} PARAM_TYPE;
typedef enum
{
FLAG_NONE = 0,
FLAG_HIDDEN = 1
} PARAM_FLAG;
typedef struct
{
char const *category;
char const *name;
char const *unit;
s32fp min;
s32fp max;
s32fp def;
uint32_t id;
} Attributes;
int Set(PARAM_NUM ParamNum, s32fp ParamVal);
s32fp Get(PARAM_NUM ParamNum);
int GetInt(PARAM_NUM ParamNum);
float GetFloat(PARAM_NUM ParamNum);
bool GetBool(PARAM_NUM ParamNum);
void SetInt(PARAM_NUM ParamNum, int ParamVal);
void SetFixed(PARAM_NUM ParamNum, s32fp ParamVal);
void SetFloat(PARAM_NUM ParamNum, float ParamVal);
PARAM_NUM NumFromString(const char *name);
PARAM_NUM NumFromId(uint32_t id);
const Attributes *GetAttrib(PARAM_NUM ParamNum);
int IsParam(PARAM_NUM ParamNum);
void LoadDefaults();
void SetFlagsRaw(PARAM_NUM param, uint8_t rawFlags);
void SetFlag(PARAM_NUM param, PARAM_FLAG flag);
void ClearFlag(PARAM_NUM param, PARAM_FLAG flag);
PARAM_FLAG GetFlag(PARAM_NUM param);
//User defined callback
void Change(Param::PARAM_NUM ParamNum);
}
#endif //PARAM_H_INCLUDED
+93
View File
@@ -0,0 +1,93 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2018 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIREGULATOR_H
#define PIREGULATOR_H
#include "my_fp.h"
#include "my_math.h"
class PiController
{
public:
/** Default constructor */
PiController();
/** Set regulator proportional and integral gain.
* \param kp New value to set for proportional gain
* \param ki New value for integral gain
*/
void SetGains(int kp, int ki)
{
this->kp = kp;
this->ki = ki;
}
void SetProportionalGain(int kp) { this->kp = kp; }
void SetIntegralGain(int ki) { this->ki = ki; }
/** Set regulator target set point
* \param val regulator target
*/
void SetRef(s32fp val) { refVal = val; }
s32fp GetRef() { return refVal; }
/** Set maximum controller output
* \param val actuator saturation value
*/
void SetMinMaxY(int32_t valMin, int32_t valMax) { minY = valMin; maxY = valMax; }
/** Set calling frequency
* \param val New value to set
*/
void SetCallingFrequency(int val) { frequency = val; }
/** Run controller to obtain a new actuator value
* \param curVal currently measured value
* \return new actuator value
*/
int32_t Run(s32fp curVal);
/** Run controller to obtain a new actuator value, run only proportional part
* \param curVal currently measured value
* \return new actuator value
*/
int32_t RunProportionalOnly(s32fp curVal);
/** Reset integrator to 0 */
void ResetIntegrator() { esum = 0; }
/** Preload Integrator to yield a certain output
* @pre SetCallingFrequency() and SetGains() must be called first
*/
void PreloadIntegrator(int32_t yieldedOutput) { esum = ki != 0 ? FP_FROMINT((yieldedOutput * frequency) / ki) : 0; }
protected:
private:
int32_t kp; //!< Proportional controller gain
int32_t ki; //!< Integral controller gain
s32fp esum; //!< Integrator
s32fp refVal; //!< control target
int32_t frequency; //!< Calling frequency
int32_t maxY; //!< upper actuator saturation value
int32_t minY; //!< lower actuator saturation value
};
#endif // PIREGULATOR_H
+40
View File
@@ -0,0 +1,40 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PRINTF_H_INCLUDED
#define PRINTF_H_INCLUDED
#if T_DEBUG
#define debugf(...) printf(__VA_ARGS__)
#else
#define debugf(...)
#endif
class IPutChar
{
public:
virtual void PutChar(char c) = 0;
};
int printf(const char *format, ...);
int sprintf(char *out, const char *format, ...);
int fprintf(IPutChar* put, const char *format, ...);
#endif // PRINTF_H_INCLUDED
File diff suppressed because it is too large Load Diff
+144
View File
@@ -0,0 +1,144 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2016 Nail Güzel
* Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STM32_CAN_H_INCLUDED
#define STM32_CAN_H_INCLUDED
#include "params.h"
#define CAN_ERR_INVALID_ID -1
#define CAN_ERR_INVALID_OFS -2
#define CAN_ERR_INVALID_LEN -3
#define CAN_ERR_MAXMESSAGES -4
#define CAN_ERR_MAXITEMS -5
#ifndef MAX_ITEMS
#define MAX_ITEMS 70
#endif // MAX_ITEMS_PER_MESSAGE
#ifndef MAX_MESSAGES
#define MAX_MESSAGES 10
#endif // MAX_MESSAGES
#ifndef SENDBUFFER_LEN
#define SENDBUFFER_LEN 20
#endif // SENDBUFFER_LEN
#ifndef MAX_USER_MESSAGES
#define MAX_USER_MESSAGES 10
#endif // MAX_USER_MESSAGES
class CANIDMAP;
class SENDBUFFER;
class Can
{
public:
enum baudrates
{
Baud125, Baud250, Baud500, Baud800, Baud1000, BaudLast
};
Can(uint32_t baseAddr, enum baudrates baudrate, bool remap = false);
void Clear(void);
void SetBaudrate(enum baudrates baudrate);
void Send(uint32_t canId, uint32_t data[2]) { Send(canId, data, 8); }
void Send(uint32_t canId, uint8_t data[8], uint8_t len) { Send(canId, (uint32_t*)data, len); }
void Send(uint32_t canId, uint32_t data[2], uint8_t len);
void SendAll();
void SDOWrite(uint8_t remoteNodeId, uint16_t index, uint8_t subIndex, uint32_t data);
void Save();
void SetReceiveCallback(void (*recv)(uint32_t, uint32_t*));
bool RegisterUserMessage(uint32_t canId);
void ClearUserMessages();
uint32_t GetLastRxTimestamp();
int AddSend(Param::PARAM_NUM param, uint32_t canId, uint8_t offsetBits, uint8_t length, float gain);
int AddRecv(Param::PARAM_NUM param, uint32_t canId, uint8_t offsetBits, uint8_t length, float gain);
int AddSend(Param::PARAM_NUM param, uint32_t canId, uint8_t offsetBits, uint8_t length, float gain, int8_t offset);
int AddRecv(Param::PARAM_NUM param, uint32_t canId, uint8_t offsetBits, uint8_t length, float gain, int8_t offset);
int Remove(Param::PARAM_NUM param);
bool FindMap(Param::PARAM_NUM param, uint32_t& canId, uint8_t& offset, uint8_t& length, float& gain, bool& rx);
void IterateCanMap(void (*callback)(Param::PARAM_NUM, uint32_t, uint8_t, uint8_t, float, bool));
void HandleRx(int fifo);
void HandleTx();
void SetNodeId(uint8_t id) { nodeId = id; }
static Can* GetInterface(int index);
private:
static volatile bool isSaving;
struct CANPOS
{
float gain;
uint16_t mapParam;
int8_t offset;
uint8_t offsetBits;
uint8_t numBits;
uint8_t next;
};
struct CANIDMAP
{
#ifdef CAN_EXT
uint32_t canId;
#else
uint16_t canId;
#endif // CAN_EXT
uint8_t first;
};
struct SENDBUFFER
{
uint32_t id;
uint32_t len;
uint32_t data[2];
};
CANIDMAP canSendMap[MAX_MESSAGES];
CANIDMAP canRecvMap[MAX_MESSAGES];
CANPOS canPosMap[MAX_ITEMS + 1]; //Last item is a "tail"
uint32_t lastRxTimestamp;
SENDBUFFER sendBuffer[SENDBUFFER_LEN];
int sendCnt;
void (*recvCallback)(uint32_t, uint32_t*);
uint16_t userIds[MAX_USER_MESSAGES];
int nextUserMessageIndex;
uint32_t canDev;
uint8_t nodeId;
void ProcessSDO(uint32_t data[2]);
void ClearMap(CANIDMAP *canMap);
int RemoveFromMap(CANIDMAP *canMap, Param::PARAM_NUM param);
int Add(CANIDMAP *canMap, Param::PARAM_NUM param, uint32_t canId, uint8_t offsetBits, uint8_t length, float gain, int8_t offset);
uint32_t SaveToFlash(uint32_t baseAddress, uint32_t* data, int len);
int LoadFromFlash();
CANIDMAP *FindById(CANIDMAP *canMap, uint32_t canId);
int CopyIdMapExcept(CANIDMAP *source, CANIDMAP *dest, Param::PARAM_NUM param);
void ReplaceParamEnumByUid(CANIDMAP *canMap);
void ReplaceParamUidByEnum(CANIDMAP *canMap);
void ConfigureFilters();
void SetFilterBank(int& idIndex, int& filterId, uint16_t* idList);
void SetFilterBank29(int& idIndex, int& filterId, uint32_t* idList);
uint32_t GetFlashAddress();
static Can* interfaces[];
};
#endif
+46
View File
@@ -0,0 +1,46 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2018 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STM32_LOADER_H_INCLUDED
#define STM32_LOADER_H_INCLUDED
#include <stdint.h>
#define PINDEF_BLKNUM 3 //3rd to last flash page
#define PINDEF_BLKSIZE 1024
#define NUM_PIN_COMMANDS 10
#define PIN_IN 0
#define PIN_OUT 1
struct pindef
{
uint32_t port;
uint16_t pin;
uint8_t inout;
uint8_t level;
};
struct pincommands
{
struct pindef pindef[NUM_PIN_COMMANDS];
uint32_t crc;
};
#define PINDEF_NUMWORDS (sizeof(struct pindef) * NUM_PIN_COMMANDS / 4)
#endif // STM32_LOADER_H_INCLUDED
+62
View File
@@ -0,0 +1,62 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2017 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STM32SCHEDULER_H
#define STM32SCHEDULER_H
#include <stdint.h>
#include <libopencm3/stm32/timer.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/stm32/rcc.h>
#define MAX_TASKS 4
/** @brief Schedules up to 4 tasks using a timer peripheral */
class Stm32Scheduler
{
public:
/** @brief construct a new scheduler using given timer
* @pre Timer clock and NVIC interrupt must be enabled
* @param timer Address of timer peripheral to use
*/
Stm32Scheduler(uint32_t timer);
/** @brief Add a periodic task, can be called up to 4 times
* @param function the task function
* @param period The calling period in 100*ms
*/
void AddTask(void (*function)(void), uint16_t period);
/** @brief Run the scheduler, must be called by the scheduler timer ISR */
void Run();
/** @brief Return CPU load caused by scheduler tasks
* @return load in 0.1%
*/
int GetCpuLoad();
protected:
private:
static const enum tim_oc_id ocMap[MAX_TASKS];
void (*functions[MAX_TASKS]) (void);
uint16_t periods[MAX_TASKS];
uint16_t execTicks[MAX_TASKS];
uint32_t timer;
int nextTask;
};
#endif // STM32SCHEDULER_H
+81
View File
@@ -0,0 +1,81 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2011 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TERMINAL_H
#define TERMINAL_H
#include <stdint.h>
#include "printf.h"
class Terminal;
typedef struct
{
char const *cmd;
void (*CmdFunc)(Terminal*, char*);
} TERM_CMD;
class Terminal: public IPutChar
{
public:
Terminal(uint32_t usart, const TERM_CMD* commands, bool remap = false);
void SetNodeId(uint8_t id);
void Run();
void PutChar(char c);
bool KeyPressed();
void FlushInput();
void DisableTxDMA();
static Terminal* defaultTerminal;
private:
struct HwInfo
{
uint32_t usart;
uint8_t dmatx;
uint8_t dmarx;
uint32_t port;
uint16_t pin;
uint32_t port_re;
uint16_t pin_re;
};
void ResetDMA();
const TERM_CMD *CmdLookup(char *buf);
void EnableUart(char* arg);
void FastUart(char* arg);
void Send(const char *str);
static const int bufSize = 128;
static const HwInfo hwInfo[];
const HwInfo* hw;
uint32_t usart;
bool remap;
const TERM_CMD* termCmds;
uint8_t nodeId;
bool enabled;
bool txDmaEnabled;
const TERM_CMD *pCurCmd;
int lastIdx;
uint8_t curBuf;
uint32_t curIdx;
bool firstSend;
char inBuf[bufSize];
char outBuf[2][bufSize]; //double buffering
char args[bufSize];
};
#endif // TERMINAL_H
+42
View File
@@ -0,0 +1,42 @@
/*
* This file is part of the libopeninv project.
*
* Copyright (C) 2021 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TERMINALCOMMANDS_H
#define TERMINALCOMMANDS_H
class TerminalCommands
{
public:
static void ParamSet(Terminal* term, char* arg);
static void ParamGet(Terminal* term, char *arg);
static void ParamFlag(Terminal* term, char *arg);
static void ParamStream(Terminal* term, char *arg);
static void PrintParamsJson(Terminal* term, char *arg);
static void MapCan(Terminal* term, char *arg);
static void SaveParameters(Terminal* term, char *arg);
static void LoadParameters(Terminal* term, char *arg);
static void Reset(Terminal* term, char *arg);
protected:
private:
static void PrintCanMap(Param::PARAM_NUM param, uint32_t canid, uint8_t offset, uint8_t length, float gain, bool rx);
};
#endif // TERMINALCOMMANDS_H