Skip to content

Commit cf0fade

Browse files
authored
Merge branch 'main' into direct_optimizer_python
2 parents 62252a7 + bd8f912 commit cf0fade

File tree

18 files changed

+295
-46
lines changed

18 files changed

+295
-46
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
$cmake_extra_args
6969
- name: Build MuJoCo MPC
7070
working-directory: build
71-
run: cmake --build . --config=Release ${{ matrix.cmake_build_args }} --target mjpc agent_test cost_derivatives_test norm_test rollout_test threadpool_test trajectory_test utilities_test direct_force_test direct_optimize_test direct_parameter_test direct_sensor_test direct_trajectory_test direct_utilities_test batch_filter_test batch_prior_test kalman_test unscented_test ${{ matrix.additional_targets }}
71+
run: cmake --build . --config=Release ${{ matrix.cmake_build_args }} --target mjpc agent_test agent_utilities_test cost_derivatives_test norm_test rollout_test threadpool_test trajectory_test direct_force_test direct_optimize_test direct_parameter_test direct_sensor_test direct_trajectory_test direct_utilities_test batch_filter_test batch_prior_test kalman_test unscented_test cubic_test gradient_planner_test gradient_test linear_test zero_test backward_pass_test ilqg_test robust_planner_test sampling_planner_test state_test task_test utilities_test ${{ matrix.additional_targets }}
7272
- name: Test MuJoCo MPC
7373
working-directory: build
7474
run: ctest -C Release --output-on-failure .

mjpc/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,28 @@ if(APPLE)
175175
target_link_libraries(mjpc "-framework Cocoa")
176176
endif()
177177

178+
add_executable(
179+
testspeed
180+
testspeed_app.cc
181+
testspeed.h
182+
testspeed.cc
183+
)
184+
target_link_libraries(
185+
testspeed
186+
absl::flags
187+
absl::flags_parse
188+
absl::random_random
189+
absl::strings
190+
libmjpc
191+
mujoco::mujoco
192+
threadpool
193+
Threads::Threads
194+
)
195+
target_include_directories(testspeed PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
196+
target_compile_options(testspeed PUBLIC ${MJPC_COMPILE_OPTIONS})
197+
target_link_options(testspeed PRIVATE ${MJPC_LINK_OPTIONS})
198+
target_compile_definitions(testspeed PRIVATE MJSIMULATE_STATIC)
199+
178200
add_subdirectory(tasks)
179201

180202
if(BUILD_TESTING AND MJPC_BUILD_TESTS)

mjpc/agent.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ void Agent::Initialize(const mjModel* model) {
7373
if (model_) mj_deleteModel(model_);
7474
model_ = mj_copyModel(nullptr, model); // agent's copy of model
7575

76+
// check for limits on all actuators
77+
int num_missing = 0;
78+
for (int i = 0; i < model_->nu; i++) {
79+
if (!model_->actuator_ctrllimited[i]) {
80+
num_missing++;
81+
printf("%s (actuator %i) missing limits\n",
82+
model_->names + model_->name_actuatoradr[i], i);
83+
}
84+
}
85+
if (num_missing > 0) {
86+
mju_error("Ctrl limits required for all actuators.\n");
87+
}
88+
7689
// planner
7790
planner_ = GetNumberOrDefault(0, model, "agent_planner");
7891

mjpc/direct/direct.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef MJPC_DIRECT_OPTIMIZER_H_
16-
#define MJPC_DIRECT_OPTIMIZER_H_
15+
#ifndef MJPC_DIRECT_DIRECT_H_
16+
#define MJPC_DIRECT_DIRECT_H_
1717

1818
#include <memory>
1919
#include <string>
@@ -64,7 +64,7 @@ class Direct {
6464
: model_parameters_(LoadModelParameters()), pool_(num_threads) {}
6565

6666
// constructor
67-
Direct(const mjModel* model, int length = 3, int max_history = 0);
67+
explicit Direct(const mjModel* model, int length = 3, int max_history = 0);
6868

6969
// destructor
7070
virtual ~Direct() {
@@ -509,4 +509,4 @@ std::string StatusString(int code);
509509

510510
} // namespace mjpc
511511

512-
#endif // MJPC_DIRECT_OPTIMIZER_H_
512+
#endif // MJPC_DIRECT_DIRECT_H_

mjpc/planners/gradient/planner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef MJPC_PLANNERS_GRADIENT_OPTIMIZER_H_
16-
#define MJPC_PLANNERS_GRADIENT_OPTIMIZER_H_
15+
#ifndef MJPC_PLANNERS_GRADIENT_PLANNER_H_
16+
#define MJPC_PLANNERS_GRADIENT_PLANNER_H_
1717

1818
#include <memory>
1919
#include <shared_mutex>
@@ -164,4 +164,4 @@ class GradientPlanner : public Planner {
164164

165165
} // namespace mjpc
166166

167-
#endif // MJPC_PLANNERS_GRADIENT_OPTIMIZER_H_
167+
#endif // MJPC_PLANNERS_GRADIENT_PLANNER_H_

mjpc/planners/ilqg/planner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef MJPC_PLANNERS_ILQG_OPTIMIZER_H_
16-
#define MJPC_PLANNERS_ILQG_OPTIMIZER_H_
15+
#ifndef MJPC_PLANNERS_ILQG_PLANNER_H_
16+
#define MJPC_PLANNERS_ILQG_PLANNER_H_
1717

1818
#include <shared_mutex>
1919
#include <vector>
@@ -161,4 +161,4 @@ class iLQGPlanner : public Planner {
161161

162162
} // namespace mjpc
163163

164-
#endif // MJPC_PLANNERS_ILQG_OPTIMIZER_H_
164+
#endif // MJPC_PLANNERS_ILQG_PLANNER_H_

mjpc/planners/ilqs/planner.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ void iLQSPlanner::OptimizePolicy(int horizon, ThreadPool& pool) {
114114
if (dim_actions != sampling.model->nu * (horizon - 1) ||
115115
dim_parameters != sampling.model->nu * num_spline_points) {
116116
// dimension
117-
int dim_parameters = sampling.model->nu * num_spline_points;
118-
int dim_actions = sampling.model->nu * (horizon - 1);
117+
dim_parameters = sampling.model->nu * num_spline_points;
118+
dim_actions = sampling.model->nu * (horizon - 1);
119119

120120
// compute parameter to action mapping
121121
mappings[sampling.policy.representation]->Compute(

mjpc/planners/ilqs/planner.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef MJPC_PLANNERS_ILQS_OPTIMIZER_H_
16-
#define MJPC_PLANNERS_ILQS_OPTIMIZER_H_
15+
#ifndef MJPC_PLANNERS_ILQS_PLANNER_H_
16+
#define MJPC_PLANNERS_ILQS_PLANNER_H_
1717

1818
#include <mujoco/mujoco.h>
1919

20+
#include <memory>
2021
#include <shared_mutex>
2122
#include <vector>
2223

@@ -110,4 +111,4 @@ class iLQSPlanner : public Planner {
110111

111112
} // namespace mjpc
112113

113-
#endif // MJPC_PLANNERS_ILQS_OPTIMIZER_H_
114+
#endif // MJPC_PLANNERS_ILQS_PLANNER_H_

mjpc/planners/sampling/planner.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,10 @@ void SamplingPlanner::Plots(mjvFigure* fig_planner, mjvFigure* fig_timer,
433433

434434
// ----- timer ----- //
435435

436-
PlotUpdateData(
437-
fig_timer, timer_bounds, fig_timer->linedata[0 + timer_shift][0] + 1,
438-
1.0e-3 * noise_compute_time * planning, 100, 0 + timer_shift, 0, 1, -100);
436+
PlotUpdateData(fig_timer, timer_bounds,
437+
fig_timer->linedata[0 + timer_shift][0] + 1,
438+
1.0e-3 * noise_compute_time * planning, 100,
439+
0 + timer_shift, 0, 1, -100);
439440

440441
PlotUpdateData(fig_timer, timer_bounds,
441442
fig_timer->linedata[1 + timer_shift][0] + 1,

mjpc/tasks/cube/cube_3x3x3.xml.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ diff --git a/cube_3x3x3_modified.xml b/cube_3x3x3_modified.xml
2323
<default class="cubelet">
2424
- <joint type="ball" armature="0.0001" damping="0.0005" frictionloss="0.001"/>
2525
- <geom type="mesh" condim="1" mesh="cubelet" euler="0 0 90"/>
26-
+ <joint type="ball" armature="0.00005" damping="0.0001" frictionloss="0.00005"/>
26+
+ <joint type="ball" armature="0.0001" damping="0.0005" frictionloss="0.00005"/>
2727
+ <geom type="mesh" condim="1" mesh="cubelet" quat="1 0 0 1"/>
2828
</default>
2929
<default class="core">

0 commit comments

Comments
 (0)