Skip to content

Commit 052caa3

Browse files
authored
Add support for new averaged cell measurements (#14)
ABS firmware v1.2.0 added the new `MEAS#:VOLT:AVG?` and `MEAS#:CURR:AVG?` commands which return a 10-sample rolling average of measured cell voltage and current. These values are the same as the ones returned over CAN when averaging is enabled. At the default control/sampling rate of 1kHz, this is a 10ms rolling average. These can be useful for applications with incredibly fast current/voltage transients which can be smoothed out by averaging.
2 parents df1d316 + e4182ed commit 052caa3

4 files changed

Lines changed: 414 additions & 0 deletions

File tree

include/bci/abs/CInterface.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ typedef struct AbsSerialDiscoveryResult {
197197
* functionality based on library version, particularly in wrappers (such as
198198
* Python).
199199
*
200+
* @since v1.1.0
201+
*
200202
* @return The library version.
201203
*/
202204
unsigned int AbsScpiClient_Version();
@@ -913,6 +915,96 @@ int AbsScpiClient_MeasureAllCellCurrents(AbsScpiClientHandle handle,
913915
float currents_out[],
914916
unsigned int count);
915917

918+
/**
919+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
920+
* a single cell.
921+
*
922+
* At the default sample rate, this is a 10ms window. With filtering on, the
923+
* length of this window will change.
924+
*
925+
* @since v1.1.0
926+
*
927+
* @par Requires
928+
* Firmware v1.2.0
929+
*
930+
* @param[in] handle SCPI client
931+
* @param[in] cell target cell index, 0-7
932+
* @param[out] voltage_out pointer to the returned average voltage
933+
*
934+
* @return 0 on success or a negative error code.
935+
*/
936+
int AbsScpiClient_MeasureAverageCellVoltage(AbsScpiClientHandle handle,
937+
unsigned int cell,
938+
float* voltage_out);
939+
940+
/**
941+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
942+
* many cells.
943+
*
944+
* At the default sample rate, this is a 10ms window. With filtering on, the
945+
* length of this window will change.
946+
*
947+
* @since v1.1.0
948+
*
949+
* @par Requires
950+
* Firmware v1.2.0
951+
*
952+
* @param[in] handle SCPI client
953+
* @param[out] voltages_out array to store the returned average voltages, one
954+
* per cell
955+
* @param[in] count the number of cells to measure
956+
*
957+
* @return 0 on success or a negative error code.
958+
*/
959+
int AbsScpiClient_MeasureAllAverageCellVoltages(AbsScpiClientHandle handle,
960+
float voltages_out[],
961+
unsigned int count);
962+
963+
/**
964+
* @brief Retrieve the rolling average of the last 10 current measurements for
965+
* a single cell.
966+
*
967+
* At the default sample rate, this is a 10ms window. With filtering on, the
968+
* length of this window will change.
969+
*
970+
* @since v1.1.0
971+
*
972+
* @par Requires
973+
* Firmware v1.2.0
974+
*
975+
* @param[in] handle SCPI client
976+
* @param[in] cell target cell index, 0-7
977+
* @param[out] current_out pointer to the returned average current
978+
*
979+
* @return 0 on success or a negative error code.
980+
*/
981+
int AbsScpiClient_MeasureAverageCellCurrent(AbsScpiClientHandle handle,
982+
unsigned int cell,
983+
float* current_out);
984+
985+
/**
986+
* @brief Retrieve the rolling average of the last 10 current measurements for
987+
* many cells.
988+
*
989+
* At the default sample rate, this is a 10ms window. With filtering on, the
990+
* length of this window will change.
991+
*
992+
* @since v1.1.0
993+
*
994+
* @par Requires
995+
* Firmware v1.2.0
996+
*
997+
* @param[in] handle SCPI client
998+
* @param[out] currents_out array to store the returned average currents, one
999+
* per cell
1000+
* @param[in] count the number of cells to measure
1001+
*
1002+
* @return 0 on success or a negative error code.
1003+
*/
1004+
int AbsScpiClient_MeasureAllAverageCellCurrents(AbsScpiClientHandle handle,
1005+
float currents_out[],
1006+
unsigned int count);
1007+
9161008
/**
9171009
* @brief Query a cell's operating mode (constant voltage or current-limited).
9181010
*

include/bci/abs/ScpiClient.h

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ScpiClient {
5757
* @brief Get the library version as a decimal integer. For example, version
5858
* 1.3.2 would return 10302.
5959
*
60+
* @since v1.1.0
61+
*
6062
* @return Library version.
6163
*/
6264
static unsigned int Version() noexcept;
@@ -985,6 +987,200 @@ class ScpiClient {
985987
*/
986988
ErrorCode MeasureAllCellCurrents(std::span<float> currents) const;
987989

990+
/**
991+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
992+
* a single cell.
993+
*
994+
* At the default sample rate, this is a 10ms window. With filtering on, the
995+
* length of this window will change.
996+
*
997+
* @since v1.1.0
998+
*
999+
* @par Requires
1000+
* Firmware v1.2.0
1001+
*
1002+
* @param[in] cell target cell index
1003+
*
1004+
* @return Result containing the average cell voltage or an error code.
1005+
*/
1006+
Result<float> MeasureAverageCellVoltage(unsigned int cell) const;
1007+
1008+
/**
1009+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
1010+
* all cells.
1011+
*
1012+
* At the default sample rate, this is a 10ms window. With filtering on, the
1013+
* length of this window will change.
1014+
*
1015+
* @since v1.1.0
1016+
*
1017+
* @par Requires
1018+
* Firmware v1.2.0
1019+
*
1020+
* @return Result containing an array of average cell voltages or an error
1021+
* code.
1022+
*/
1023+
Result<std::array<float, kCellCount>> MeasureAllAverageCellVoltages() const;
1024+
1025+
/**
1026+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
1027+
* all cells.
1028+
*
1029+
* At the default sample rate, this is a 10ms window. With filtering on, the
1030+
* length of this window will change.
1031+
*
1032+
* @note It is recommended that the array and span overloads be preferred over
1033+
* this overload whenever possible.
1034+
*
1035+
* @since v1.1.0
1036+
*
1037+
* @par Requires
1038+
* Firmware v1.2.0
1039+
*
1040+
* @param[out] voltages array to store the average voltages
1041+
* @param[in] count length of the array (must not be greater than the total
1042+
* cell count)
1043+
*
1044+
* @return An error code.
1045+
*/
1046+
ErrorCode MeasureAllAverageCellVoltages(float* voltages,
1047+
std::size_t count) const;
1048+
1049+
/**
1050+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
1051+
* all cells.
1052+
*
1053+
* At the default sample rate, this is a 10ms window. With filtering on, the
1054+
* length of this window will change.
1055+
*
1056+
* @since v1.1.0
1057+
*
1058+
* @par Requires
1059+
* Firmware v1.2.0
1060+
*
1061+
* @param[out] voltages an array of average cell voltages
1062+
*
1063+
* @return An error code.
1064+
*/
1065+
ErrorCode MeasureAllAverageCellVoltages(
1066+
std::array<float, kCellCount>& voltages) const;
1067+
1068+
/**
1069+
* @brief Retrieve the rolling average of the last 10 voltage measurements for
1070+
* all cells.
1071+
*
1072+
* At the default sample rate, this is a 10ms window. With filtering on, the
1073+
* length of this window will change.
1074+
*
1075+
* @since v1.1.0
1076+
*
1077+
* @par Requires
1078+
* Firmware v1.2.0
1079+
*
1080+
* @param[out] voltages an array of cell voltages (must not be longer than the
1081+
* total cell count)
1082+
*
1083+
* @return An error code.
1084+
*/
1085+
ErrorCode MeasureAllAverageCellVoltages(std::span<float> voltages) const;
1086+
1087+
/**
1088+
* @brief Retrieve the rolling average of the last 10 current measurements for
1089+
* a single cell.
1090+
*
1091+
* At the default sample rate, this is a 10ms window. With filtering on, the
1092+
* length of this window will change.
1093+
*
1094+
* @since v1.1.0
1095+
*
1096+
* @par Requires
1097+
* Firmware v1.2.0
1098+
*
1099+
* @param[in] cell target cell index
1100+
*
1101+
* @return Result containing the average cell current or an error code.
1102+
*/
1103+
Result<float> MeasureAverageCellCurrent(unsigned int cell) const;
1104+
1105+
/**
1106+
* @brief Retrieve the rolling average of the last 10 current measurements for
1107+
* all cells.
1108+
*
1109+
* At the default sample rate, this is a 10ms window. With filtering on, the
1110+
* length of this window will change.
1111+
*
1112+
* @since v1.1.0
1113+
*
1114+
* @par Requires
1115+
* Firmware v1.2.0
1116+
*
1117+
* @return Result containing an array of average cell currents or an error
1118+
* code.
1119+
*/
1120+
Result<std::array<float, kCellCount>> MeasureAllAverageCellCurrents() const;
1121+
1122+
/**
1123+
* @brief Retrieve the rolling average of the last 10 current measurements for
1124+
* all cells.
1125+
*
1126+
* At the default sample rate, this is a 10ms window. With filtering on, the
1127+
* length of this window will change.
1128+
*
1129+
* @note It is recommended that the array and span overloads be preferred over
1130+
* this overload whenever possible.
1131+
*
1132+
* @since v1.1.0
1133+
*
1134+
* @par Requires
1135+
* Firmware v1.2.0
1136+
*
1137+
* @param[out] currents array to store the average currents
1138+
* @param[in] count length of the array (must not be greater than the total
1139+
* cell count)
1140+
*
1141+
* @return An error code.
1142+
*/
1143+
ErrorCode MeasureAllAverageCellCurrents(float* currents,
1144+
std::size_t count) const;
1145+
1146+
/**
1147+
* @brief Retrieve the rolling average of the last 10 current measurements for
1148+
* all cells.
1149+
*
1150+
* At the default sample rate, this is a 10ms window. With filtering on, the
1151+
* length of this window will change.
1152+
*
1153+
* @since v1.1.0
1154+
*
1155+
* @par Requires
1156+
* Firmware v1.2.0
1157+
*
1158+
* @param[out] currents an array of average cell currents
1159+
*
1160+
* @return An error code.
1161+
*/
1162+
ErrorCode MeasureAllAverageCellCurrents(
1163+
std::array<float, kCellCount>& currents) const;
1164+
1165+
/**
1166+
* @brief Retrieve the rolling average of the last 10 current measurements for
1167+
* all cells.
1168+
*
1169+
* At the default sample rate, this is a 10ms window. With filtering on, the
1170+
* length of this window will change.
1171+
*
1172+
* @since v1.1.0
1173+
*
1174+
* @par Requires
1175+
* Firmware v1.2.0
1176+
*
1177+
* @param[out] currents an array of cell currents (must not be longer than the
1178+
* total cell count)
1179+
*
1180+
* @return An error code.
1181+
*/
1182+
ErrorCode MeasureAllAverageCellCurrents(std::span<float> currents) const;
1183+
9881184
/**
9891185
* @brief Query a single cell's operating mode.
9901186
*

src/CInterface.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,32 @@ int AbsScpiClient_MeasureAllCellCurrents(AbsScpiClientHandle handle,
609609
static_cast<std::size_t>(count));
610610
}
611611

612+
int AbsScpiClient_MeasureAverageCellVoltage(AbsScpiClientHandle handle,
613+
unsigned int cell,
614+
float* voltage_out) {
615+
return WrapGet(&sc::MeasureAverageCellVoltage, handle, voltage_out, cell);
616+
}
617+
618+
int AbsScpiClient_MeasureAllAverageCellVoltages(AbsScpiClientHandle handle,
619+
float voltages_out[],
620+
unsigned int count) {
621+
return WrapGet(&sc::MeasureAllAverageCellVoltages, handle, voltages_out,
622+
static_cast<std::size_t>(count));
623+
}
624+
625+
int AbsScpiClient_MeasureAverageCellCurrent(AbsScpiClientHandle handle,
626+
unsigned int cell,
627+
float* current_out) {
628+
return WrapGet(&sc::MeasureAverageCellCurrent, handle, current_out, cell);
629+
}
630+
631+
int AbsScpiClient_MeasureAllAverageCellCurrents(AbsScpiClientHandle handle,
632+
float currents_out[],
633+
unsigned int count) {
634+
return WrapGet(&sc::MeasureAllAverageCellCurrents, handle, currents_out,
635+
static_cast<std::size_t>(count));
636+
}
637+
612638
static_assert(ABS_CELL_MODE_CV == static_cast<int>(CellMode::kConstantVoltage));
613639
static_assert(ABS_CELL_MODE_ILIM ==
614640
static_cast<int>(CellMode::kCurrentLimited));

0 commit comments

Comments
 (0)