Page MenuHomec4science

escon_drive.c
No OneTemporary

File Metadata

Created
Sun, Feb 23, 01:32

escon_drive.c

#include "escon_drive.h"
#include "dac.h"
#include "../lib/utils.h"
// Motors parameters for the maxon EC-max 30mm 24V.
#define MOTOR_NOMINAL_CURRENT 2.66f // [A].
#define MOTOR_TORQUE_CONSTANT 0.0243f // [N.m/A].
#define ESCON_CURRENT_FACTOR (9.0f/MOTOR_NOMINAL_CURRENT) // [V/A].
/**
* @brief Intializes the driver.
* Initializes the driver, and set the motor torque to zero.
*/
void esc_Init(void)
{
// Set the motor torque to zero.
dac_SetVoltage1(0.0f);
}
/**
* @brief Sets the motor torque.
* @param torque the torque to set [N.m]. If larger than the nominal torque, it
* will be saturated to the nominal torque.
*/
void esc_SetTorque(float32_t torque)
{
// Compute the motor current.
float32_t motorCurrent = torque / MOTOR_TORQUE_CONSTANT; // [A].
utils_SaturateF(&motorCurrent,
-MOTOR_NOMINAL_CURRENT, MOTOR_NOMINAL_CURRENT);
// Compute the equivalent voltage.
dac_SetVoltage1(motorCurrent * ESCON_CURRENT_FACTOR);
}

Event Timeline