Erste Vorbereitungen für Settings-Datei
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include <settings/settings.h>
|
||||
#include <can/can_client.h>
|
||||
#include <io/io.h>
|
||||
#include <mqtt/mqtt_client.h>
|
||||
|
||||
int iCanSimu = 0;
|
||||
|
||||
struct MOTOR_CONTROL_DATA motctrl[MOTOR_COUNT];
|
||||
struct CAN_INTERFACE_DATA intf_data[MOTOR_COUNT];
|
||||
struct MOTOR_CONTROL_DATA motctrl[MAX_MOTOR_COUNT];
|
||||
struct CAN_INTERFACE_DATA intf_data[MAX_MOTOR_COUNT];
|
||||
|
||||
|
||||
int iBusTimeoutCounter = 0;
|
||||
@@ -47,7 +48,8 @@ int Can_OpenInterface(int iMotorIndex, const char * ifacename)
|
||||
motctrl[iMotorIndex].nDriveConnected = 0;
|
||||
motctrl[iMotorIndex].nDriveReady = 0;
|
||||
|
||||
mylog(LOG_INFO, "CAN: PWR_MAX_RAW=%d PWR_STEP_COUNT=%d", MOTOR_PWR_MAX_RAW, MOTOR_PWR_STEP_COUNT);
|
||||
mylog(LOG_INFO, "CAN: PWR_MIN_RAW=%d PWR_MAX_RAW=%d PWR_STEP_COUNT=%d",
|
||||
settings.iMotorPwrMinRaw, settings.iMotorPwrMaxRaw, settings.iMotorPwrStepCount);
|
||||
|
||||
strcpy(intf_data[iMotorIndex].iface_name, ifacename);
|
||||
Can_SetMotorGear(iMotorIndex, MOTOR_GEAR_NEUTRAL);
|
||||
@@ -177,7 +179,7 @@ void Can_SetMotorGear(int iMotorIndex, int iGear)
|
||||
|
||||
/// @brief Set power for the given motor
|
||||
/// @param iMotorIndex
|
||||
/// @param iPower (Range: 0..MOTOR_PWR_STEP_COUNT)
|
||||
/// @param iPower (Range: 0..settings.iMotorPwrStepCount)
|
||||
void Can_SetMotorPower(int iMotorIndex, int iPower)
|
||||
{
|
||||
if ((motctrl[iMotorIndex].iMotorGear == MOTOR_GEAR_NEUTRAL) || (motctrl[iMotorIndex].nDriveReady == 0))
|
||||
@@ -190,10 +192,10 @@ void Can_SetMotorPower(int iMotorIndex, int iPower)
|
||||
// limit to min. power
|
||||
motctrl[iMotorIndex].iMotorPowerSteps = 1;
|
||||
}
|
||||
else if (iPower >= MOTOR_PWR_STEP_COUNT)
|
||||
else if (iPower >= settings.iMotorPwrStepCount)
|
||||
{
|
||||
// limit to max. power
|
||||
motctrl[iMotorIndex].iMotorPowerSteps = MOTOR_PWR_STEP_COUNT;
|
||||
motctrl[iMotorIndex].iMotorPowerSteps = settings.iMotorPwrStepCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -208,7 +210,16 @@ void Can_SetMotorPower(int iMotorIndex, int iPower)
|
||||
}
|
||||
else
|
||||
{
|
||||
motctrl[iMotorIndex].iMotorPowerRaw = (((MOTOR_PWR_MAX_RAW - MOTOR_PWR_MIN_RAW) * (motctrl[iMotorIndex].iMotorPowerSteps - 1)) / (MOTOR_PWR_STEP_COUNT - 1)) + MOTOR_PWR_MIN_RAW;
|
||||
// Scale motor power from steps to raw value
|
||||
motctrl[iMotorIndex].iMotorPowerRaw = (((settings.iMotorPwrMaxRaw - settings.iMotorPwrMinRaw) * (motctrl[iMotorIndex].iMotorPowerSteps - 1)) / (settings.iMotorPwrStepCount - 1)) + settings.iMotorPwrMinRaw;
|
||||
if (motctrl[iMotorIndex].iMotorPowerRaw < settings.iMotorPwrMinRaw)
|
||||
{
|
||||
motctrl[iMotorIndex].iMotorPowerRaw = settings.iMotorPwrMinRaw;
|
||||
}
|
||||
else if (motctrl[iMotorIndex].iMotorPowerRaw > settings.iMotorPwrMaxRaw)
|
||||
{
|
||||
motctrl[iMotorIndex].iMotorPowerRaw = settings.iMotorPwrMaxRaw;
|
||||
}
|
||||
}
|
||||
|
||||
mylog(LOG_INFO, "CAN: Motor[%d]: Set power to %d -> %d",
|
||||
|
||||
Reference in New Issue
Block a user