Skip to content

Commit

Permalink
[driver] resistance
Browse files Browse the repository at this point in the history
  • Loading branch information
Lham42 committed Jun 22, 2024
1 parent 77a9d8f commit 226bfca
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 52 deletions.
95 changes: 52 additions & 43 deletions driver/ni/ai_channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ static inline int32_t get_bridge_config(std::string s){
return DAQmx_Val_FullBridge;
}

static inline int32_t getResistanceConfig(std::string s){
if(s == "2Wire") return DAQmx_Val_2Wire;
if(s == "3Wire") return DAQmx_Val_3Wire;
if(s == "4Wire") return DAQmx_Val_4Wire;
return DAQmx_Val_2Wire;
}

// TODO: make one for current excitation for correct parsing
typedef struct ExcitationConfig {
int32_t voltageExcitSource;
double voltageExcitVal;
Expand Down Expand Up @@ -431,14 +439,7 @@ class CurrentRMS : public Current{
if(type == "PT3928") return DAQmx_Val_Pt3928;
if(type == "Custom") return DAQmx_Val_Custom;
return DAQmx_Val_Pt3750;
}

static int32_t getResistanceConfig(std::string s){
if(s == "2Wire") return DAQmx_Val_2Wire;
if(s == "3Wire") return DAQmx_Val_3Wire;
if(s == "4Wire") return DAQmx_Val_4Wire;
return DAQmx_Val_2Wire;
}
}

explicit RTD(config::Parser &parser, TaskHandle task_handle, std::string name)
: Analog(parser, task_handle, name),
Expand Down Expand Up @@ -703,17 +704,23 @@ class Acceleration4WireDCVoltage : public Acceleration {
}
};

/*
/// @brief acceleration channel with charge
class AccelerationCharge : public Analog {
public:
double sensitivity;
int32_t sensitivityUnits;
int32 terminal_config = 0;

explicit AccelerationCharge(config::Parser &parser, TaskHandle task_handle, std::string name)
: Analog(parser, task_handle, name),
sensitivity(parser.required<double>("sensitivity")),
sensitivityUnits(parser.required<int32_t>("sensitivity_units")) {}
terminal_config(ni::getTerminalConfig(parser.required<std::string>("terminal_config"))),
sensitivity(parser.required<double>("sensitivity")) {
std::string u = parser.optional<std::string>("units", "Volts");
this->units = ni::UNITS_MAP.at(u);

std::string su = parser.optional<std::string>("sensitivity_units", "mVoltsPerG");
this->sensitivityUnits = ni::UNITS_MAP.at(su);
}

int32 createNIChannel() override {
if(this->scale_config.type == "none"){
Expand All @@ -727,14 +734,46 @@ class AccelerationCharge : public Analog {
this->units,
this->sensitivity,
this->sensitivityUnits,
this->excitationConfig.voltageExcitSource,
this->excitationConfig.voltageExcitVal,
NULL
);
}
}
};

///////////////////////////////////////////////////////////////////////////////////
// Resistance //
///////////////////////////////////////////////////////////////////////////////////
class Resistance : public Analog{
public:
int32_t resistanceConfig;
ExcitationConfig excitationConfig;

explicit Resistance(config::Parser &parser, TaskHandle task_handle, std::string name)
: Analog(parser, task_handle, name),
resistanceConfig(getResistanceConfig(parser.required<std::string>("resistance_config"))),
excitationConfig(parser) {
std::string u = parser.optional<std::string>("units", "Volts");
this->units = ni::UNITS_MAP.at(u);
}

int32 createNIChannel() override {
if(this->scale_config.type == "none"){
return ni::NiDAQmxInterface::CreateAIResistanceChan(
this->task_handle,
this->name.c_str(),
"",
this->min_val,
this->max_val,
this->units,
this->resistanceConfig,
this->excitationConfig.voltageExcitSource,
this->excitationConfig.voltageExcitVal,
NULL
);
}
}
};
/*
///////////////////////////////////////////////////////////////////////////////////
// Bridge //
///////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1100,37 +1139,7 @@ class PressureBridgeTwoPointLin : public Analog{
}
}
///////////////////////////////////////////////////////////////////////////////////
// Resistance //
///////////////////////////////////////////////////////////////////////////////////
class Resistance : public Analog{
public:
int32_t resistanceConfig;
ExcitationConfig excitationConfig;
explicit Resistance(config::Parser &parser, TaskHandle task_handle, std::string name)
: Analog(parser, task_handle, name),
resistanceConfig(parser),
excitationConfig(parser) {}
int32 createNIChannel() override {
if(this->scale_config.type == "none"){
return ni::NiDAQmxInterface::CreateAIResistanceChan(
this->task_handle,
this->name.c_str(),
"",
this->min_val,
this->max_val,
this->units,
this->resistanceConfig,
this->excitationConfig.voltageExcitSource,
this->excitationConfig.voltageExcitVal,
NULL
);
}
}
}
///////////////////////////////////////////////////////////////////////////////////
// Rosette Strain Gage //
Expand Down
12 changes: 6 additions & 6 deletions driver/ni/analog_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ std::shared_ptr<ni::Analog> ni::AnalogReadSource::parseChannel(
if (channel_type == "ai_accel_4_wire_dc_voltage") {
return std::make_shared<Acceleration4WireDCVoltage>(parser, this->task_handle, channel_name);
}
// if (channel_type == "ai_accel_charge") {
// return std::make_shared<AccelerationCharge>(parser, this->task_handle, channel_name);
// }
if (channel_type == "ai_accel_charge") {
return std::make_shared<AccelerationCharge>(parser, this->task_handle, channel_name);
}
// if (channel_type == "ai_bridge") {
// return std::make_shared<Bridge>(parser, this->task_handle, channel_name);
// }
Expand Down Expand Up @@ -94,9 +94,9 @@ std::shared_ptr<ni::Analog> ni::AnalogReadSource::parseChannel(
// if (channel_type == "ai_pressure_bridge_two_point_lin") {
// return std::make_shared<PressureBridgeTwoPointLin>(parser, this->task_handle, channel_name);
// }
// if (channel_type == "ai_resistance") {
// return std::make_shared<Resistance>(parser, this->task_handle, channel_name);
// }
if (channel_type == "ai_resistance") {
return std::make_shared<Resistance>(parser, this->task_handle, channel_name);
}
// if (channel_type == "ai_rosette_strain_gage") {
// return std::make_shared<RosetteStrainGage>(parser, this->task_handle, channel_name);
// }
Expand Down
73 changes: 70 additions & 3 deletions driver/ni/analog_read_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,20 +1142,21 @@ TEST(read_tests, one_acceleration_channel){
}

///@brief Acceleration 4 wire dc voltage
// TODO: find devices which support this channel
TEST(read_tests, one_acceleration_4_wire_channel){
// Create NI readerconfig json
auto config = json{
{"sample_rate", 100},
{"stream_rate", 20},
{"device_location", "Dev9"},
{"device_location", "Dev10"},
{"type", "ni_analog_read"},
{"test", true},
{"device", ""}
};

auto channel_config = json{
{"name", "test_ni_channel"},
{"type", "ai_accel"},
{"type", "ai_accel_4_wire_dc_voltage"},
{"port", 0},
{"max_val", 100.0},
{"min_val", -100.0},
Expand All @@ -1173,10 +1174,45 @@ TEST(read_tests, one_acceleration_4_wire_channel){
auto scale_config = json{
{"type","none"}
};
analog_channel_helper(config, scale_config, channel_config);
// analog_channel_helper(config, scale_config, channel_config);
}

///@brief Acceleration Charge
// TODO: find devices which support this channel
TEST(read_tests, one_acceleration_charge_channel){
// Create NI readerconfig json
auto config = json{
{"sample_rate", 100},
{"stream_rate", 20},
{"device_location", "Dev11"},
{"type", "ni_analog_read"},
{"test", true},
{"device", ""}
};

auto channel_config = json{
{"name", "test_ni_channel"},
{"type", "ai_accel_charge"},
{"port", 0},
{"max_val", 100.0},
{"min_val", -100.0},
{"units", "AccelUnit_g"},
{"enabled", true},
{"key", "key"},
{"terminal_config", "Default"}, // TODO try pseudo differential
{"voltage_excit_source","Internal"},
{"voltage_excit_val", 0.0},
{"sensitivity", 50},
{"sensitivity_units", "mVoltsPerG"},
{"use_excit_for_scaling", false}
};

auto scale_config = json{
{"type","none"}
};
// analog_channel_helper(config, scale_config, channel_config);
}


///@brief Force Bridge Polynomial

Expand Down Expand Up @@ -1356,6 +1392,37 @@ TEST(read_tests, one_current_RMS_channel){
///@brief pressure bridge linear

///@brief resistance
TEST(read_tests, one_resistance_channel){
// Create NI readerconfig json
auto config = json{
{"sample_rate", 5},
{"stream_rate", 1},
{"device_location", "Dev3"},
{"type", "ni_analog_read"},
{"test", true},
{"device", ""}
};

auto channel_config = json{
{"name", "test_ni_channel"},
{"type", "ai_resistance"},
{"port", 0},
{"max_val", 10000},
{"min_val", 0},
{"units", "Ohms"},
{"enabled", true},
{"key", "key"},
{"voltage_excit_source","Internal"},
{"voltage_excit_val", 0.0005},
{"resistance_config", "2Wire"},
};

auto scale_config = json{
{"type","none"}
};

analog_channel_helper(config, scale_config, channel_config);
}

///@brief rosette strain gauge

Expand Down

0 comments on commit 226bfca

Please sign in to comment.