Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ci:
autoupdate_branch: devel
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
- id: ruff
args:
Expand All @@ -19,7 +19,7 @@ repos:
- id: toml-sort-fix
exclude: poetry.lock
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.6
rev: v19.1.7
hooks:
- id: clang-format
args:
Expand Down
24 changes: 7 additions & 17 deletions include/hpp/manipulation/device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,17 @@ namespace manipulation {
///
/// This class also contains pinocchio::Gripper, Handle and \ref
/// JointAndShapes_t
class HPP_MANIPULATION_DLLAPI Device : public pinocchio::HumanoidRobot {
class HPP_MANIPULATION_DLLAPI Device
: public pinocchio::HumanoidRobot,
public std::enable_shared_from_this<Device> {
public:
typedef pinocchio::HumanoidRobot Parent_t;

/// Constructor
/// \param name of the new instance,
static DevicePtr_t create(const std::string& name) {
Device* ptr = new Device(name);
DevicePtr_t shPtr(ptr);
ptr->init(shPtr);
return shPtr;
}
static DevicePtr_t create(const std::string& name);

DevicePtr_t self() const { return self_.lock(); }
DevicePtr_t self() { return shared_from_this(); }

/// Print object in a stream
virtual std::ostream& print(std::ostream& os) const;
Expand All @@ -84,24 +81,17 @@ class HPP_MANIPULATION_DLLAPI Device : public pinocchio::HumanoidRobot {
/// \param name of the new instance,
/// \param robot Robots that manipulate objects,
/// \param objects Set of objects manipulated by the robot.
Device(const std::string& name) : Parent_t(name) {}
Device(const std::string& name);

void init(const DeviceWkPtr_t& self) {
Parent_t::init(self);
self_ = self;
}
void init(const DeviceWkPtr_t& self) { Parent_t::init(self); }

void initCopy(const DeviceWkPtr_t& self, const Device& other) {
Parent_t::initCopy(self, other);
self_ = self;
}

/// For serialization only
Device() {}

private:
DeviceWkPtr_t self_;

HPP_SERIALIZABLE();
}; // class Device
} // namespace manipulation
Expand Down
13 changes: 11 additions & 2 deletions src/device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ namespace hpp {
namespace manipulation {
using ::pinocchio::Frame;

DevicePtr_t Device::create(const std::string& name) {
Device* ptr = new Device(name);
DevicePtr_t shPtr(ptr);
ptr->init(shPtr);
return shPtr;
}

Device::Device(const std::string& name) : Parent_t(name) {}

pinocchio::DevicePtr_t Device::clone() const {
Device* ptr = new Device(*this);
DevicePtr_t shPtr(ptr);
Expand Down Expand Up @@ -130,7 +139,8 @@ void Device::removeJoints(const std::vector<std::string>& jointNames,
Parent_t::removeJoints(jointNames, referenceConfig);

for (auto& pair : grippers.map)
pair.second = pinocchio::Gripper::create(pair.second->name(), self_);
pair.second =
pinocchio::Gripper::create(pair.second->name(), shared_from_this());
// TODO update handles and jointAndShapes
}

Expand Down Expand Up @@ -160,7 +170,6 @@ void Device::serialize(Archive& ar, const unsigned int version) {
name_, false) != this);
ar& BOOST_SERIALIZATION_NVP(written);
if (written) {
ar& BOOST_SERIALIZATION_NVP(self_);
// TODO (easy) add serialization of core::Container ?
// ar & BOOST_SERIALIZATION_NVP(handles);
// ar & BOOST_SERIALIZATION_NVP(grippers);
Expand Down
Loading