Skip to content

Commit

Permalink
Fix some OD warnings on Controller_motor example
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Aug 28, 2023
1 parent 90402a9 commit 4f35b1e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ void ll_motor_enable(char state)
******************************************************************************/
void ll_motor_Command(uint16_t mode, float ratio)
{
float current = ll_motor_GetCurrent();
float currentfactor = 1.0f;
currentfactor = *motor_parameters.limit_current / (current * 2);
current_t current = ElectricOD_CurrentFrom_A(ll_motor_GetCurrent());
float currentfactor;
currentfactor = motor_parameters.limit_current->raw / (current.raw * 2.0f);
static float surpCurrentSum = 0.0;
float surpCurrent = current - *motor_parameters.limit_current;
const float surpCurrent = current.raw - motor_parameters.limit_current->raw;
surpCurrentSum += surpCurrent;
// If surpCurrentSum > 0 do a real coef
if (surpCurrentSum > 0.0)
{
currentfactor = *motor_parameters.limit_current / (*motor_parameters.limit_current + (surpCurrentSum / 1.5));
currentfactor = motor_parameters.limit_current->raw / (motor_parameters.limit_current->raw + (surpCurrentSum / 1.5));
}
else
{
Expand All @@ -228,10 +228,10 @@ void ll_motor_Command(uint16_t mode, float ratio)
}

// limit power value
if (ratio < -*motor_parameters.limit_ratio)
ratio = -*motor_parameters.limit_ratio;
if (ratio > *motor_parameters.limit_ratio)
ratio = *motor_parameters.limit_ratio;
if (ratio < -motor_parameters.limit_ratio->raw)
ratio = -motor_parameters.limit_ratio->raw;
if (ratio > motor_parameters.limit_ratio->raw)
ratio = motor_parameters.limit_ratio->raw;

// transform power ratio to timer value
uint16_t pulse;
Expand Down Expand Up @@ -278,7 +278,7 @@ float ll_motor_GetAngularPosition(void)
******************************************************************************/
float ll_motor_GetLinearPosition(float angular_position)
{
return angular_position / 360.0 * M_PI * (*motor_parameters.wheel_diameter);
return angular_position / 360.0 * M_PI * LinearOD_PositionTo_m(*motor_parameters.wheel_diameter);
}

/******************************************************************************
Expand All @@ -294,11 +294,11 @@ void ll_motor_config(motor_config_t motor_config)
motor_parameters.limit_ratio = motor_config.limit_ratio;
motor_parameters.limit_current = motor_config.limit_current;

// default motor configuration
// Default motor configuration
*motor_parameters.motor_reduction = 131;
*motor_parameters.resolution = 16;
*motor_parameters.wheel_diameter = 0.100f;
// default motor hardware limits
*motor_parameters.limit_ratio = 100.0;
*motor_parameters.limit_current = 6.0;
}
*motor_parameters.wheel_diameter = LinearOD_PositionFrom_m(0.100f);
// Default motor hardware limits
*motor_parameters.limit_ratio = RatioOD_RatioFrom_Percent(100.0f);
*motor_parameters.limit_current = ElectricOD_CurrentFrom_A(6.0f);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef _LL_MOTOR_H
#define _LL_MOTOR_H

#include "float.h"
#include "luos_engine.h"
#include "stdio.h"

/*******************************************************************************
Expand Down Expand Up @@ -44,11 +44,11 @@ typedef struct motor_config
// motor configuration
float *motor_reduction;
float *resolution;
float *wheel_diameter;
linear_position_t *wheel_diameter;

// hardware limits
float *limit_ratio;
float *limit_current;
ratio_t *limit_ratio;
current_t *limit_current;
} motor_config_t;
/*******************************************************************************
* Variables
Expand All @@ -65,4 +65,4 @@ float ll_motor_GetAngularPosition(void);
float ll_motor_GetLinearPosition(float);
void ll_motor_config(motor_config_t);

#endif /* _LL_MOTOR_H */
#endif /* _LL_MOTOR_H */

0 comments on commit 4f35b1e

Please sign in to comment.