Motion Master 6.0.0-alpha.111
Next-generation motion control software
Loading...
Searching...
No Matches
plant_identification.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <expected>
6#include <functional>
7#include <nlohmann/json.hpp>
8#include <optional>
9#include <span>
10#include <string>
11#include <string_view>
12#include <vector>
13
14#include "node/somanet_drive.h"
15
25
26namespace mm::node {
27
33 std::vector<double> torquesNm;
34 std::vector<double> velocitiesRadPerSecond;
35};
36
39 std::vector<double> numerator;
40 std::vector<double> denominator;
44 nlohmann::json bode;
45};
46
54using PlantModelFitFn = std::function<std::expected<PlantModelFit, std::string>(
55 const PlantMeasurement& measurement, double startFrequencyHz, double endFrequencyHz)>;
56
58inline constexpr std::string_view kPlantModelFile = "plant_model.csv";
59
65inline constexpr std::chrono::milliseconds kChirpPaddingMs{200};
66
68inline constexpr double kMinMeanAbsTorquePermil = 10.0;
69
71inline constexpr double kMinMeanAbsVelocityRadPerSecond = 0.5;
72
75inline constexpr double kLowMeanAbsVelocityRadPerSecond = 6.0;
76
85void to_json(nlohmann::json& j, const PlantModelChirp& chirp);
86
94struct PlantModel {
95 std::vector<double> numerator;
96 std::vector<double> denominator;
98
101 std::optional<double> inertia() const;
102
105 std::optional<double> friction() const;
106};
107void to_json(nlohmann::json& j, const PlantModel& model);
108
114std::expected<std::chrono::milliseconds, std::string> plantIdentificationStreamDuration(
115 std::chrono::milliseconds transitionTime);
116
122PlantMeasurement convertPlantMeasurement(std::span<const HrdSystemIdentificationSample> samples,
123 uint32_t ratedTorqueMilliNm);
124
137std::expected<std::optional<std::string>, std::string> checkPlantMeasurementAmplitudes(
138 const PlantMeasurement& measurement, uint32_t ratedTorqueMilliNm);
139
146bool isStablePlantModel(std::span<const double> denominator);
147
153std::string plantModelCsv(const PlantModel& model);
154
160std::expected<PlantModel, std::string> parsePlantModelCsv(std::string_view text);
161
162} // namespace mm::node
ChirpSignalType
Which excitation the system-identification run sweeps with (parameter 4).
Definition somanet_drive.h:543
@ kLogarithmic
Logarithmic frequency sweep whose amplitude rises with it, from half the target to the target.
Definition bus_health_source.h:7
constexpr std::string_view kPlantModelFile
The file on the drive that holds the identified plant model.
Definition plant_identification.h:58
std::function< std::expected< PlantModelFit, std::string >(const PlantMeasurement &measurement, double startFrequencyHz, double endFrequencyHz)> PlantModelFitFn
Fits a plant model to a measurement.
Definition plant_identification.h:55
constexpr double kLowMeanAbsVelocityRadPerSecond
Mean absolute velocity, in rad/s, below which a recording is accepted with a warning,...
Definition plant_identification.h:75
std::expected< std::optional< std::string >, std::string > checkPlantMeasurementAmplitudes(const PlantMeasurement &measurement, uint32_t ratedTorqueMilliNm)
Checks that the recording excited the plant enough for a fit.
Definition plant_identification.cc:133
void to_json(nlohmann::json &j, const Cia402Status &s)
Serialises a Cia402Status. Emits state/modeName as human-readable strings alongside the numeric statu...
Definition cia402_drive.cc:13
PlantMeasurement convertPlantMeasurement(std::span< const HrdSystemIdentificationSample > samples, uint32_t ratedTorqueMilliNm)
Converts a recording into the units the fit takes.
Definition plant_identification.cc:120
constexpr double kMinMeanAbsTorquePermil
Mean absolute torque, in per mille of rated torque, below which a recording is refused.
Definition plant_identification.h:68
constexpr std::chrono::milliseconds kChirpPaddingMs
Recording time added around the chirp.
Definition plant_identification.h:65
std::expected< std::chrono::milliseconds, std::string > plantIdentificationStreamDuration(std::chrono::milliseconds transitionTime)
How long the HRD stream must run for a chirp of transitionTime.
Definition plant_identification.cc:106
std::expected< PlantModel, std::string > parsePlantModelCsv(std::string_view text)
Reads the text of kPlantModelFile.
Definition plant_identification.cc:173
bool isStablePlantModel(std::span< const double > denominator)
Whether a model with this denominator is stable.
Definition plant_identification.cc:161
std::string plantModelCsv(const PlantModel &model)
Renders a model as the text of kPlantModelFile.
Definition plant_identification.cc:165
constexpr double kMinMeanAbsVelocityRadPerSecond
Mean absolute velocity, in rad/s, below which a recording is refused.
Definition plant_identification.h:71
std::string text
Definition soem_fieldbus_driver.cc:1254
The recorded response of a drive to a chirp, in the units the fit takes.
Definition plant_identification.h:32
std::vector< double > velocitiesRadPerSecond
Velocity of the velocity-control encoder.
Definition plant_identification.h:34
std::vector< double > torquesNm
Actual torque, in Nm.
Definition plant_identification.h:33
The chirp a plant model was identified with, stored beside the model.
Definition plant_identification.h:78
double startFrequencyHz
Where the sweep began.
Definition plant_identification.h:79
somanet::ChirpSignalType signalType
Definition plant_identification.h:83
uint32_t durationMs
How long the sweep took.
Definition plant_identification.h:82
uint32_t amplitudePermil
Peak excitation, per mille of rated torque.
Definition plant_identification.h:81
double endFrequencyHz
Where it ended.
Definition plant_identification.h:80
A plant model as the fit returns it: a transfer function from torque to velocity.
Definition plant_identification.h:38
std::vector< double > numerator
Numerator coefficients, highest order first.
Definition plant_identification.h:39
std::vector< double > denominator
Definition plant_identification.h:40
nlohmann::json bode
Definition plant_identification.h:44
An identified plant model: the transfer function from torque in Nm to velocity in rad/s,...
Definition plant_identification.h:94
std::vector< double > numerator
Numerator coefficients, highest order first.
Definition plant_identification.h:95
std::optional< double > friction() const
The effective viscous friction: the last denominator coefficient.
Definition plant_identification.cc:89
std::optional< double > inertia() const
The effective inertia: the denominator coefficient before the last.
Definition plant_identification.cc:82
PlantModelChirp chirp
What excited the plant.
Definition plant_identification.h:97
std::vector< double > denominator
Denominator coefficients, highest order first.
Definition plant_identification.h:96