Skip to content

Commit

Permalink
ADDED second load-cell
Browse files Browse the repository at this point in the history
  • Loading branch information
IC2D base committed Aug 21, 2023
1 parent 37e1d26 commit e00d444
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 22 deletions.
18 changes: 18 additions & 0 deletions lib/forecastnucleoframework/include/forecast/IHardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ class IHardware {
app.fatal_error("Hardware setStartT() function not implemented");
}

/**
* @brief Set the experiment duration.
*
* @param duration The experiment duration (seconds)
*/
virtual inline void set_duration(float duration) {
app.fatal_error("Hardware set_duration() function not implemented");
}

/**
* @brief Return the start time of the experiment.
*
Expand All @@ -101,6 +110,15 @@ class IHardware {
app.fatal_error("Hardware getStartT() function not implemented");
}

/**
* @brief Return the hw duration time.
*
* @return duration_t
*/
virtual inline float get_duration() const {
app.fatal_error("Hardware get_duration() function not implemented");
}

/**
* @brief Return the torque applied by the motor (current feedback)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class Hardware : public IHardware {
logs["dtauS"] = &dtauS;
logs["ddtauS"] = &ddtauS;

logs["tauSensor"] = &tauSensor;
logs["dtauSensor"] = &dtauSensor;
logs["ddtauSensor"] = &ddtauSensor;
logs["F"] = &tauSensor;
logs["dF"] = &dtauSensor;
logs["ddF"] = &ddtauSensor;

logs["thetaM"] = &thetaM;
logs["dthetaM"] = &dthetaM;
logs["ddthetaM"] = &ddthetaM;
logs["x"] = &thetaM;
logs["dx"] = &dthetaM;
logs["ddx"] = &ddthetaM;

logs["thetaE"] = &thetaE;
logs["dthetaE"] = &dthetaE;
Expand Down Expand Up @@ -110,6 +110,13 @@ class Hardware : public IHardware {
*/
inline void set_start_time(float time) override { start_t = time; }

/**
* @brief Set the experiment duration.
*
* @param duration The experiment duration (seconds).
*/
inline void set_duration(float duration) override { duration_t = duration; }

/**
* @brief Return the start time of the experiment.
*
Expand All @@ -124,7 +131,14 @@ class Hardware : public IHardware {
*/
virtual inline float get_current_time() const override { return t - start_t; }

/**std::make_unique<control::Control>()
/**
* @brief Return the hw duration time.
*
* @return duration_t
*/
virtual inline float get_duration() const override { return duration_t; }

/**
* @brief Return the torque applied by the motor (current feedback)
*
* @return motorTorqueFeedback
Expand Down Expand Up @@ -296,11 +310,14 @@ class Hardware : public IHardware {
EsconMotor *env_motor = nullptr; ///< Motor used for the env. simulation

AnalogInput *torque_sensor = nullptr; ///< Torque sensor
AnalogInput *load_cell2_sensor = nullptr; ///< Torque sensor

utility::AnalogFilter* lowPassTauSensor;
utility::AnalogFilter* lowPassLoacCell2;

float t, dt, current_time;
float start_t;
float duration_t;

float tauM;
float dtauM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace motorControl {
constexpr float LINMOT_FORCE_MIN = -255.00;
constexpr float KT = (LINMOT_FORCE_MAX - LINMOT_FORCE_MIN);
constexpr float JM = 1.0000f;
constexpr float offset_bias = -0.015; // LinMot: 0.000 | Moog E024: 0.0042 | 0.000
constexpr float offset_bias = 0.00; // LinMot: 0.000 | Moog E024: -0.015
constexpr float amp_scale = 1.00;
#elif
constexpr float MAX_CURR = 3.33f;
Expand Down
1 change: 1 addition & 0 deletions lib/forecastnucleoframework/src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ bool App::exec_control_loop(unsigned long freq, float duration) {

DEBUG_INFO("Executing the control loop at frequency %luHz\n", freq);

hw->set_duration(duration);
hw->safety_off(); // putting the hardware in a ready state for the
// experiment
size_t log_size = hw_logs.size();
Expand Down
27 changes: 19 additions & 8 deletions lib/forecastnucleoframework/src/platforms/workbench/Hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ forecast::Status forecast::Hardware::init() {
if (not torqueSensorInit())
return Status::TORQUE_SENSOR_INIT_ERR;

load_cell2_sensor = new AnalogInput(PC_1);

lowPassTauSensor = utility::AnalogFilter::getLowPassFilterHz(2.0f);
lowPassTauSensor->clean();

Expand Down Expand Up @@ -164,23 +166,32 @@ void forecast::Hardware::update(float dt) {


float amplitude_voltage(1);
//float center_voltage(LOADCELL_250_OFFSET);
float center_voltage(LOADCELL_5K_OFFSET);
float center_voltage(LOADCELL_250_OFFSET);
//float center_voltage(LOADCELL_5K_OFFSET);

// Board voltage from USB: 3.324 V
// Read Load Cell 1
float signed_voltage = torque_sensor->read_average_float() * 3.324f - center_voltage;
if (signed_voltage >= 0.00f) {
amplitude_voltage = 3.324 - center_voltage;
tauSensor = signed_voltage/amplitude_voltage * LOADCELL_5K_RANGE;
tauSensor = signed_voltage/amplitude_voltage * LOADCELL_250_RANGE;
} else{
amplitude_voltage = center_voltage - 0.00;
tauSensor = signed_voltage/amplitude_voltage * LOADCELL_5K_RANGE;
tauSensor = signed_voltage/amplitude_voltage * LOADCELL_250_RANGE;
}

// Read Load Cell 2
float lc2_signed_voltage = load_cell2_sensor->read_average_float() * 3.324f - 1.749;
if (lc2_signed_voltage >= 0.00f) {
amplitude_voltage = 3.324 -1.749;
tauS = lc2_signed_voltage/amplitude_voltage * LOADCELL_5K_RANGE;
} else{
amplitude_voltage = 1.749 - 0.00;
tauS = lc2_signed_voltage/amplitude_voltage * LOADCELL_5K_RANGE;
}
tauS = lowPassLoacCell2->process(-tauS, dt);
float tauSensor_filt = lowPassTauSensor->process(tauSensor, dt);
tauSensor = tauSensor_filt + 11.0f; // Bias in Newton, hydraulic tests 2023-07-19


tauSensor = tauSensor_filt - 7.0f; // Bias in Newton, hydraulic tests 2023-07-19

dtauSensor = (tauSensor - prev_tauSensor) / dt;
ddtauSensor = (dtauSensor - prev_dtauSensor) / dt;
prev_tauSensor = tauSensor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ forecast::ConstantRefGen::ConstantRefGen(std::vector<float> v) : values(std::mov
}

std::vector<float> forecast::ConstantRefGen::process(const IHardware* hw) {
return values;
}
float time = hw->get_current_time();
float duration = hw->get_duration();

if (time > 2.0f && time < (duration - 2)) {
return values;
}
else {
return {0};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ forecast::SinusoidRefGen::SinusoidRefGen(float frequency, float amplitude) : fre
}

std::vector<float> forecast::SinusoidRefGen::process(const IHardware* hw) {
float output = (amplitude * (-1)* cos(2 * M_PI * frequency * hw->get_current_time() )) + amplitude;
float output = (amplitude * sin(2 * M_PI * frequency * hw->get_current_time() ));
return {output};
}
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <forecast/controllers/EnvRenderingControl.hpp>
#include <forecast/controllers/AdmittanceControl.hpp>
#include <forecast/controllers/ImpedanceControl.hpp>
#include <forecast/controllers/Bypass.hpp>

/** Refgen Headers */
#include <forecast/reference_generators/ConstantRefGen.hpp>
Expand Down Expand Up @@ -64,9 +65,7 @@ int main()
app.get_controller_factory().add("NoController", make_no_controller_builder());
app.get_controller_factory().add("Admittance", make_admittance_control_builder());
app.get_controller_factory().add("Impedance", make_impedance_control_builder());
//app.get_controller_factory().add("Bypass", make_Bypass_builder());

//app.get_operator_factory().add("Sum", make_sum_op_builder());
app.get_controller_factory().add("Bypass", make_Bypass_builder());

DEBUG_INFO("finished with app\n");

Expand Down

0 comments on commit e00d444

Please sign in to comment.