Skip to content

Commit

Permalink
Formatted files with clang and cpplint
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhosh committed Jun 10, 2024
1 parent 92cd7ae commit c02baaa
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 187 deletions.
7 changes: 0 additions & 7 deletions mjpc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz)
FetchContent_MakeAvailable(json)

add_library(threadpool STATIC)
target_sources(
threadpool
Expand Down Expand Up @@ -167,7 +163,6 @@ target_link_libraries(
mujoco::platform_ui_adapter
threadpool
Threads::Threads
nlohmann_json::nlohmann_json
)
target_include_directories(libmjpc
PUBLIC
Expand All @@ -189,7 +184,6 @@ target_link_libraries(
mujoco::mujoco
threadpool
Threads::Threads
nlohmann_json::nlohmann_json
)
target_include_directories(mjpc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_compile_options(mjpc PUBLIC ${MJPC_COMPILE_OPTIONS})
Expand All @@ -214,7 +208,6 @@ target_link_libraries(
mujoco::mujoco
threadpool
Threads::Threads
nlohmann_json::nlohmann_json
)
target_include_directories(libtestspeed PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..)

Expand Down
67 changes: 17 additions & 50 deletions mjpc/tasks/humanoid/interact/contact_keyframe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "contact_keyframe.h"
#include "mjpc/tasks/humanoid/interact/contact_keyframe.h"

namespace mjpc::humanoid {
void ContactPair::Reset() {
body1 = kNotSelectedInteract;
body2 = kNotSelectedInteract;
geom1 = kNotSelectedInteract;
geom2 = kNotSelectedInteract;
for (int i = 0; i < 3; i++) {
local_pos1[i] = 0.;
local_pos2[i] = 0.;
}
}

void ContactKeyframe::Reset() {
name.clear();
for (auto& contact_pair : contact_pairs)
contact_pair.Reset();

facing_target.clear();
weight.clear();
}

void to_json(json& j, const ContactPair& contact_pair) {
j = json{{"body1", contact_pair.body1},
{"body2", contact_pair.body2},
{"geom1", contact_pair.geom1},
{"geom2", contact_pair.geom2},
{"local_pos1", contact_pair.local_pos1},
{"local_pos2", contact_pair.local_pos2}};
}

void from_json(const json& j, ContactPair& contact_pair) {
j.at("body1").get_to(contact_pair.body1);
j.at("body2").get_to(contact_pair.body2);
j.at("geom1").get_to(contact_pair.geom1);
j.at("geom2").get_to(contact_pair.geom2);
j.at("local_pos1").get_to(contact_pair.local_pos1);
j.at("local_pos2").get_to(contact_pair.local_pos2);
}
void ContactPair::Reset() {
body1 = kNotSelectedInteract;
body2 = kNotSelectedInteract;
geom1 = kNotSelectedInteract;
geom2 = kNotSelectedInteract;
for (int i = 0; i < 3; i++) {
local_pos1[i] = 0.;
local_pos2[i] = 0.;
}
}

void to_json(json& j, const ContactKeyframe& keyframe) {
j = json{{"name", keyframe.name},
{"contacts", keyframe.contact_pairs},
{"facing_target", keyframe.facing_target},
{"weight", keyframe.weight}};
}
void ContactKeyframe::Reset() {
name.clear();
for (auto& contact_pair : contact_pairs) contact_pair.Reset();

void from_json(const json& j, ContactKeyframe& keyframe) {
j.at("name").get_to(keyframe.name);
j.at("contacts").get_to(keyframe.contact_pairs);
j.at("facing_target").get_to(keyframe.facing_target);
j.at("weight").get_to(keyframe.weight);
}
facing_target.clear();
weight.clear();
}
} // namespace mjpc::humanoid
64 changes: 29 additions & 35 deletions mjpc/tasks/humanoid/interact/contact_keyframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef CONTACT_KEYFRAME_H
#define CONTACT_KEYFRAME_H
#ifndef MJPC_TASKS_HUMANOID_INTERACT_CONTACT_KEYFRAME_H_
#define MJPC_TASKS_HUMANOID_INTERACT_CONTACT_KEYFRAME_H_

#include <mujoco/mujoco.h>
#include <map>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
using json = nlohmann::json;

#include "mujoco/mujoco.h"

namespace mjpc::humanoid {

Expand All @@ -27,44 +28,37 @@ constexpr int kNotSelectedInteract = -1;
constexpr int kNumberOfContactPairsInteract = 5;

class ContactPair {
public:
int body1, body2, geom1, geom2;
mjtNum local_pos1[3], local_pos2[3];
public:
int body1, body2, geom1, geom2;
mjtNum local_pos1[3], local_pos2[3];

ContactPair()
: body1(kNotSelectedInteract),
body2(kNotSelectedInteract),
geom1(kNotSelectedInteract),
geom2(kNotSelectedInteract),
local_pos1{0.},
local_pos2{0.} {}

ContactPair() : body1(kNotSelectedInteract),
body2(kNotSelectedInteract),
geom1(kNotSelectedInteract),
geom2(kNotSelectedInteract),
local_pos1{0.},
local_pos2{0.} {}

void Reset();
void Reset();
};

class ContactKeyframe {
public:
std::string name;
ContactPair contact_pairs[kNumberOfContactPairsInteract];
public:
std::string name;
ContactPair contact_pairs[kNumberOfContactPairsInteract];

// the direction on the xy-plane for the torso to point towards
std::vector<mjtNum> facing_target;

// weight of all residual terms (name -> value map)
std::map<std::string, mjtNum> weight;
// the direction on the xy-plane for the torso to point towards
std::vector<mjtNum> facing_target;

ContactKeyframe() : name(""),
contact_pairs{},
facing_target(),
weight() {}
// weight of all residual terms (name -> value map)
std::map<std::string, mjtNum> weight;

void Reset();
};
ContactKeyframe() : name(""), contact_pairs{}, facing_target(), weight() {}

void to_json(json& j, const ContactPair& contact_pair);
void from_json(const json& j, ContactPair& contact_pair);
void to_json(json& j, const ContactKeyframe& keyframe);
void from_json(const json& j, ContactKeyframe& keyframe);
void Reset();
};

} // namespace mjpc::humanoid

#endif // CONTACT_KEYFRAME_H
#endif // MJPC_TASKS_HUMANOID_INTERACT_CONTACT_KEYFRAME_H_
Loading

0 comments on commit c02baaa

Please sign in to comment.