Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.14.4 Several fixes. Better E-Stop handling #109

Merged
merged 10 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
### Changes this version:
- Only activate brake resistor if vint and vext are >6.5V. Prevents board from activating resistor if only usb powered and a fault reset loop
- Changed behaviour of direction enable and axis enable bits in set_effect report to always apply direction vector
- Fix for Forza Motorsport
- TMC E-Stop handled even during calibration by pausing and disabling driver
- E-Stop checked correctly after startup. You can now disable force and delay startup by setting E-Stop during startup.
- Digital and Analog sources are disabled by default
- Biss-C 1 rotation offset glitch at first packet fixed
- Reverted CAN retransmission to enabled temporarily. Fixes 2 axis ODrive issues.

### Changes since v1.14.0
- Save TMC space vector PWM mode in flash. Should be usually on for BLDC motors if the star point is isolated.
- Allow using the motors flux component to dissipate energy with the TMC4671 instead of the brake resistor. May cause noticable braking in the motor but takes stress off the resistor.
- Axis speed limiter usable and saved in flash.
- Removed unused hall direction flash setting.
- Added local button pulse mode
- Added local button pulse mode
- Only activate brake resistor if vint and vext are >6.5V. Prevents board from activating resistor if only usb powered and a fault reset loop
- Changed behaviour of direction enable and axis enable bits in set_effect report to always apply direction vector
- Fix for Forza Motorsport
2 changes: 1 addition & 1 deletion Configurator
22 changes: 11 additions & 11 deletions Firmware/FFBoard/Inc/ClassChooser.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ClassChooser {
*/
T* Create(uint16_t id){
T* cls = nullptr;
for(class_entry<T> e : *class_registry){
for(const class_entry<T>& e : *class_registry){

if(e.selectionId == id && e.isCreatable()){
cls = e.create();
Expand All @@ -114,7 +114,7 @@ class ClassChooser {
* Checks the isCreatable() function
*/
bool isCreatable(uint16_t id){
for(class_entry<T> e : *class_registry){
for(const class_entry<T>& e : *class_registry){
if(e.selectionId == id && e.isCreatable()){
return true;
}
Expand All @@ -127,18 +127,18 @@ class ClassChooser {
* Generates replies for the command system listing selectable classes
*/
void replyAvailableClasses(std::vector<CommandReply>& replies,int16_t ignoredCreatableId = 255){
for(class_entry<T> cls : *class_registry){
for(const class_entry<T>& cls : *class_registry){
if(cls.info.visibility == ClassVisibility::hidden || (cls.info.visibility == ClassVisibility::debug && !SystemCommands::debugMode)){
if(ignoredCreatableId != cls.selectionId)
continue;
}
std::string ret;
// std::string ret;
CommandReply replyObj;
ret+= std::to_string(cls.selectionId);
ret+= ":";
ret+= (cls.isCreatable() || ignoredCreatableId == cls.selectionId) ? "1" : "0";
ret+= ":";
ret+= cls.info.name;
replyObj.reply+= std::to_string(cls.selectionId);
replyObj.reply+= ":";
replyObj.reply+= (cls.isCreatable() || ignoredCreatableId == cls.selectionId) ? "1" : "0";
replyObj.reply+= ":";
replyObj.reply+= cls.info.name;

if(cls.isCreatable()){
replyObj.type = CommandReplyType::STRING_OR_DOUBLEINT;
Expand All @@ -147,7 +147,7 @@ class ClassChooser {
}else{
replyObj.type = CommandReplyType::STRING;
}
replyObj.reply = ret;
// replyObj.reply = ret;
replies.push_back(replyObj);
}
}
Expand All @@ -157,7 +157,7 @@ class ClassChooser {
* Returns if this id is actually in the list of possible classes
*/
bool isValidClassId(uint16_t id){
for(class_entry<T> cls : *class_registry){
for(const class_entry<T>& cls : *class_registry){
if(cls.selectionId == id){
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions Firmware/FFBoard/Inc/I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class I2CPort : public I2CHandler, public CommandHandler, public PersistentStora
bool readMemIT(I2CDevice* device,const uint16_t devAddr,const uint16_t memAddr,const uint16_t memAddSize,uint8_t* pData,const uint16_t size,bool shiftAddr = true);
bool writeMemIT(I2CDevice* device,const uint16_t devAddr,const uint16_t memAddr,const uint16_t memAddSize,uint8_t* pData,const uint16_t size,bool shiftAddr = true);

bool isDeviceReady(I2CDevice* device,const uint16_t devAddr,const uint32_t trials,uint32_t timeout,bool shiftAddr = true);

void takeSemaphore();
void giveSemaphore();
bool isTaken();
Expand Down
2 changes: 1 addition & 1 deletion Firmware/FFBoard/Inc/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* For more settings see target_constants.h in a target specific folder
*/

static const uint8_t SW_VERSION_INT[3] = {1,14,3}; // Version as array. 8 bit each!
static const uint8_t SW_VERSION_INT[3] = {1,14,4}; // Version as array. 8 bit each!
#define MAX_AXIS 2 // ONLY USE 2 for now else screws HID Reports
#define FLASH_VERSION 0 // Counter to increase whenever a full flash erase is required.

Expand Down
8 changes: 8 additions & 0 deletions Firmware/FFBoard/Src/I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ bool I2CPort::writeMemIT(I2CDevice* device,const uint16_t devAddr,const uint16_t
return flag;
}

bool I2CPort::isDeviceReady(I2CDevice* device,const uint16_t devAddr,const uint32_t trials,uint32_t timeout,bool shiftAddr){
currentDevice = device;
device->startI2CTransfer(this);
bool flag = HAL_I2C_IsDeviceReady(&this->hi2c, shiftAddr ? devAddr << 1 : devAddr, trials,timeout) == HAL_OK;
device->endI2CTransfer(this);
return flag;
}

void I2CPort::I2cTxCplt(I2C_HandleTypeDef *hi2c){
if (currentDevice == nullptr) {
return;
Expand Down
3 changes: 2 additions & 1 deletion Firmware/FFBoard/UserExtensions/Inc/EncoderLocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "CommandHandler.h"
#include "PersistentStorage.h"

#ifdef LOCALENCODER
extern TIM_HandleTypeDef TIM_ENC;


Expand Down Expand Up @@ -64,5 +65,5 @@ class EncoderLocal: public Encoder,public ExtiHandler,TimerHandler,public Comman
bool indexHit = false;
bool useIndex = false;
};

#endif
#endif /* ENCODERLOCAL_H_ */
4 changes: 2 additions & 2 deletions Firmware/FFBoard/UserExtensions/Inc/FFBHIDMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class FFBHIDMain: public FFBoardMain, public cpp_freertos::Thread, PersistentSto
uint8_t reportSendCounter = 0;

const uint8_t analogAxisCount = 8;
uint16_t btnsources = 1; // Default ID0 = local buttons
uint16_t ainsources = 1;
uint16_t btnsources = 0; // Disabled by default
uint16_t ainsources = 0;


ClassChooser<ButtonSource> btn_chooser;
Expand Down
5 changes: 5 additions & 0 deletions Firmware/FFBoard/UserExtensions/Src/EncoderBissC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ EncoderBissC::EncoderBissC() :
}

void EncoderBissC::Run(){
bool first = true;
while(true){
requestNewDataSem.Take(); // Wait until a position is requested
waitData = true;
Expand All @@ -49,6 +50,10 @@ void EncoderBissC::Run(){

if(updateFrame()){
pos = newPos;
if(first){ // Prevent immediate multiturn update
lastPos = pos;
first = false;
}
//handle multiturn
if(pos-lastPos > 1<<(lenghtDataBit-1)){
mtpos--;
Expand Down
3 changes: 2 additions & 1 deletion Firmware/FFBoard/UserExtensions/Src/EncoderLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "EncoderLocal.h"
#include "flash_helpers.h"

#ifdef LOCALENCODER
bool EncoderLocal::inUse = false;
ClassIdentifier EncoderLocal::info = {
.name = "Local ABN" ,
Expand Down Expand Up @@ -144,3 +144,4 @@ CommandStatus EncoderLocal::command(const ParsedCommand& cmd,std::vector<Command

return CommandStatus::OK;
}
#endif
17 changes: 8 additions & 9 deletions Firmware/FFBoard/UserExtensions/Src/FFBHIDMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,6 @@ FFBHIDMain::FFBHIDMain(uint8_t axisCount) :
restoreFlash(); // Load parameters
registerCommands();


#ifdef E_STOP_Pin
bool estopState = HAL_GPIO_ReadPin(E_STOP_GPIO_Port, E_STOP_Pin) == GPIO_PIN_RESET;
if(estopState){ // Estop pressed at startup
emergencyStop(!estopState);
lastEstop = HAL_GetTick();
}
#endif

}

/**
Expand Down Expand Up @@ -138,6 +129,14 @@ void FFBHIDMain::saveFlash(){


void FFBHIDMain::Run(){
#ifdef E_STOP_Pin
bool estopState = HAL_GPIO_ReadPin(E_STOP_GPIO_Port, E_STOP_Pin) == GPIO_PIN_RESET;
if(estopState){ // Estop pressed at startup
emergencyStop(!estopState);
// control.emergency = true; // Immediately enter emergency state but without notifying other classes yet
lastEstop = HAL_GetTick();
}
#endif
while(true){
Delay(1);
updateControl();
Expand Down
45 changes: 26 additions & 19 deletions Firmware/FFBoard/UserExtensions/Src/TMC4671.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void TMC4671::Run(){
case TMC_ControlState::uninitialized:
allowStateChange = false;
// check communication and write constants
if(!pingDriver()){ // driver not available
if(!pingDriver() || emergency){ // driver not available or emergency was set before startup
initialized = false; // Assume driver is not initialized if we can not detect it
Delay(250);
break;
Expand All @@ -456,7 +456,7 @@ void TMC4671::Run(){
pulseClipLed(); // blink led
static uint8_t powerCheckCounter = 0;
// if powered check ADCs and go to encoder calibration
if(!hasPower()){
if(!hasPower() || emergency){
powerCheckCounter = 0;
Delay(250);
break;
Expand Down Expand Up @@ -634,6 +634,10 @@ void TMC4671::Run(){
flagCheckInProgress = false;
}
Delay(10);

if(emergency && !motorReady()){
this->Suspend(); // we can not safely run. wait until resumed by estop
}
} // End while
}

Expand Down Expand Up @@ -1650,7 +1654,7 @@ void TMC4671::setUdUq(int16_t ud,int16_t uq){
void TMC4671::stopMotor(){
// Stop driver if running

//enablePin.reset();
enablePin.reset();
motorEnabledRequested = false;
if(state == TMC_ControlState::Running || state == TMC_ControlState::EncoderFinished){
setMotionMode(MotionMode::stop,true);
Expand All @@ -1660,43 +1664,46 @@ void TMC4671::stopMotor(){
}
void TMC4671::startMotor(){
motorEnabledRequested = true;
if(!initialized || emergency){
//initialize();
emergency = false;
// if(state != TMC_ControlState::Init_wait)
// changeState(TMC_ControlState::Init_wait);
}

if(state == TMC_ControlState::Shutdown && initialized && encoderAligned){
changeState(TMC_ControlState::Running);
}
// Start driver if powered
if(hasPower()){
// Start driver if powered and emergency flag reset
if(hasPower() && !emergency){
setPwm(TMC_PwmMode::PWM_FOC); // enable foc
enablePin.set();
setMotionMode(nextMotionMode,true);

}
// else{
// changeState(TMC_ControlState::waitPower);
// }
else{
changeState(TMC_ControlState::waitPower);
}

}

void TMC4671::emergencyStop(bool reset){
if(!reset){
setPwm(TMC_PwmMode::HSlow_LShigh); // Short low side for instant stop
// setPwm(TMC_PwmMode::HSlow_LShigh); // Short low side for instant stop
emergency = true;
enablePin.reset(); // Release enable pin to disable the whole driver
motorEnabledRequested = false;
this->stopMotor();

}else{
enablePin.set();
setPwm(TMC_PwmMode::PWM_FOC);
// enablePin.set();
// writeReg(0x64, 0); // Set flux and torque 0 directly. Make sure motor does not jump
// setPwm(TMC_PwmMode::PWM_FOC);
emergency = false;
motorEnabledRequested = true;
//this->changeState(TMC_ControlState::waitPower, true); // Reinit
this->startMotor();

if(!motorReady()){
if(inIsr()){
ResumeFromISR();
}else{
Resume();
}
}
}
}

Expand Down Expand Up @@ -2043,7 +2050,7 @@ int16_t TMC4671::getFlux(){
return readReg(0x64) && 0xffff;
}
void TMC4671::setFluxTorque(int16_t flux, int16_t torque){
if(curMotionMode != MotionMode::torque){
if(curMotionMode != MotionMode::torque && !emergency){
setMotionMode(MotionMode::torque,true);
}
writeReg(0x64, (flux & 0xffff) | (torque << 16));
Expand Down
2 changes: 1 addition & 1 deletion Firmware/Targets/F407VG/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static void MX_CAN1_Init(void)
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.AutoRetransmission = ENABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
Expand Down
2 changes: 1 addition & 1 deletion Firmware/Targets/F407VG/OpenFFBoard_F407VG.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ CAN1.CalculateTimeBit=2000
CAN1.CalculateTimeQuantum=142.85714285714286
CAN1.IPParameters=Prescaler,BS1,SJW,TTCM,ABOM,AWUM,NART,RFLM,TXFP,Mode,CalculateTimeQuantum,BS2,CalculateTimeBit,CalculateBaudRate
CAN1.Mode=CAN_MODE_NORMAL
CAN1.NART=DISABLE
CAN1.NART=ENABLE
CAN1.Prescaler=6
CAN1.RFLM=DISABLE
CAN1.SJW=CAN_SJW_1TQ
Expand Down
2 changes: 1 addition & 1 deletion Firmware/Targets/F407VG_DISCO/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ static void MX_CAN1_Init(void)
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.AutoRetransmission = ENABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
Expand Down
2 changes: 1 addition & 1 deletion Firmware/Targets/F407VG_DISCO/OpenFFBoard_F407VG_DISCO.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CAN1.CalculateTimeBit=2000
CAN1.CalculateTimeQuantum=142.85714285714286
CAN1.IPParameters=Prescaler,BS1,SJW,TTCM,ABOM,AWUM,NART,RFLM,TXFP,Mode,CalculateTimeQuantum,BS2,CalculateTimeBit,CalculateBaudRate
CAN1.Mode=CAN_MODE_NORMAL
CAN1.NART=DISABLE
CAN1.NART=ENABLE
CAN1.Prescaler=6
CAN1.RFLM=DISABLE
CAN1.SJW=CAN_SJW_1TQ
Expand Down
Loading