Skip to content

Commit d8dd9ae

Browse files
authored
Merge branch 'main' into ps_py
2 parents e013da4 + 0809835 commit d8dd9ae

File tree

16 files changed

+246
-1308
lines changed

16 files changed

+246
-1308
lines changed

mjpc/direct/direct.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ void Direct::Initialize(const mjModel* model) {
6464
}
6565

6666
// timestep
67-
this->model->opt.timestep = GetNumberOrDefault(this->model->opt.timestep,
68-
model, "estimator_timestep");
67+
this->model->opt.timestep =
68+
GetNumberOrDefault(this->model->opt.timestep, model, "direct_timestep");
6969

7070
// length of configuration trajectory
7171
configuration_length_ =
72-
GetNumberOrDefault(3, model, "batch_configuration_length");
72+
GetNumberOrDefault(3, model, "direct_configuration_length");
7373

7474
// check configuration length
7575
if (configuration_length_ > max_history_) {

mjpc/estimators/batch.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ void Batch::Initialize(const mjModel* model) {
4949
// base method
5050
Direct::Initialize(model);
5151

52+
// set batch size
53+
int batch_size = std::min(
54+
std::max(GetNumberOrDefault(3, model, "batch_configuration_length"),
55+
kMinDirectHistory),
56+
kMaxFilterHistory);
57+
58+
if (batch_size != configuration_length_) {
59+
SetConfigurationLength(batch_size);
60+
}
61+
5262
// allocation dimension
5363
int nq = model->nq, nv = model->nv, na = model->na;
5464
int nvel_max = nv * max_history_;

mjpc/estimators/batch.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
namespace mjpc {
3333

3434
// max filter history
35-
inline constexpr int kMaxFilterHistory = 32;
35+
inline constexpr int kMaxFilterHistory = 128;
3636

3737
// ----- batch estimator ----- //
3838
// based on: "Physically-Consistent Sensor Fusion in Contact-Rich Behaviors"
@@ -78,6 +78,11 @@ class Batch : public Direct, public Estimator {
7878
// get data
7979
mjData* Data() override { return data_[0].get(); };
8080

81+
// get qfrc
82+
double* Qfrc() override {
83+
return force_prediction.Get(configuration_length_ - 2);
84+
};
85+
8186
// get process noise
8287
double* ProcessNoise() override { return noise_process.data(); };
8388

mjpc/estimators/estimator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class Estimator {
6060
// get data
6161
virtual mjData* Data() = 0;
6262

63+
// get qfrc
64+
virtual double* Qfrc() = 0;
65+
6366
// process noise
6467
virtual double* ProcessNoise() = 0;
6568

@@ -220,6 +223,9 @@ class GroundTruth : public Estimator {
220223
// get data
221224
mjData* Data() override { return data_; };
222225

226+
// get qfrc
227+
double* Qfrc() override { return data_->qfrc_actuator; }
228+
223229
// get process noise
224230
double* ProcessNoise() override { return noise_process.data(); };
225231

mjpc/estimators/kalman.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class Kalman : public Estimator {
8080
// get data
8181
mjData* Data() override { return data_; };
8282

83+
// get qfrc
84+
double* Qfrc() override { return data_->qfrc_actuator; };
85+
8386
// get process noise
8487
double* ProcessNoise() override { return noise_process.data(); };
8588

mjpc/estimators/unscented.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void Unscented::Initialize(const mjModel* model) {
3737
if (this->data_) mj_deleteData(this->data_);
3838
data_ = mj_makeData(model);
3939

40+
// settings
41+
settings.alpha = GetNumberOrDefault(1.0, model, "unscented_alpha");
42+
settings.beta = GetNumberOrDefault(2.0, model, "unscented_beta");
43+
4044
// timestep
4145
this->model->opt.timestep = GetNumberOrDefault(this->model->opt.timestep,
4246
model, "estimator_timestep");

mjpc/estimators/unscented.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class Unscented : public Estimator {
8181
// get data
8282
mjData* Data() override { return data_; };
8383

84+
// get qfrc
85+
double* Qfrc() override { return data_->qfrc_actuator; };
86+
8487
// get process noise
8588
double* ProcessNoise() override { return noise_process.data(); };
8689

mjpc/grpc/filter.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ message UpdateResponse {}
5656
message State {
5757
repeated double state = 1 [packed = true];
5858
optional double time = 2;
59+
repeated double qfrc = 3 [packed = true];
5960
}
6061

6162
message StateRequest {

mjpc/grpc/filter_service.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ grpc::Status FilterService::State(grpc::ServerContext* context,
174174
// get time
175175
output->set_time(active_filter->Time());
176176

177+
// get qfrc
178+
double* qfrc = active_filter->Qfrc();
179+
for (int i = 0; i < model->nv; i++) {
180+
output->add_qfrc(qfrc[i]);
181+
}
182+
177183
return grpc::Status::OK;
178184
}
179185

0 commit comments

Comments
 (0)