diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ea0e06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Copyright 2025 Enactic, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +/.vscode +/build \ No newline at end of file diff --git a/include/openarm/can/socket/arm_component.hpp b/include/openarm/can/socket/arm_component.hpp index 34688fd..c9c7159 100644 --- a/include/openarm/can/socket/arm_component.hpp +++ b/include/openarm/can/socket/arm_component.hpp @@ -27,9 +27,9 @@ public: ArmComponent(canbus::CANSocket& can_socket); ~ArmComponent() = default; - void init_motor_devices(std::vector motor_types, - std::vector send_can_ids, std::vector recv_can_ids, - bool use_fd); + void init_motor_devices(const std::vector& motor_types, + const std::vector& send_can_ids, + const std::vector& recv_can_ids, bool use_fd); private: std::vector motors_; diff --git a/include/openarm/can/socket/openarm.hpp b/include/openarm/can/socket/openarm.hpp index b61f974..5f7b8e5 100644 --- a/include/openarm/can/socket/openarm.hpp +++ b/include/openarm/can/socket/openarm.hpp @@ -48,6 +48,8 @@ public: void disable_all(); void set_zero_all(); void refresh_all(); + + void refresh_one(int i); // The timeout for reading from socket, set to timeout_us. // Tuning this value may improve the performance but should be done with caution. void recv_all(int timeout_us = 500); diff --git a/include/openarm/damiao_motor/dm_motor_device_collection.hpp b/include/openarm/damiao_motor/dm_motor_device_collection.hpp index dde4407..6ff4224 100644 --- a/include/openarm/damiao_motor/dm_motor_device_collection.hpp +++ b/include/openarm/damiao_motor/dm_motor_device_collection.hpp @@ -32,9 +32,12 @@ public: // Common motor operations void enable_all(); void disable_all(); - void set_zero_all(); void set_callback_mode_all(CallbackMode callback_mode); + // Flash new zero position + void set_zero(int i); + void set_zero_all(); + // Refresh operations (for individual motors) void refresh_one(int i); void refresh_all(); @@ -49,6 +52,7 @@ public: // Device collection access std::vector get_motors() const; + Motor get_motor(int i) const; canbus::CANDeviceCollection& get_device_collection() { return *device_collection_; } protected: diff --git a/src/openarm/can/socket/arm_component.cpp b/src/openarm/can/socket/arm_component.cpp index 1a2471b..fd2dc1a 100644 --- a/src/openarm/can/socket/arm_component.cpp +++ b/src/openarm/can/socket/arm_component.cpp @@ -23,9 +23,9 @@ namespace openarm::can::socket { ArmComponent::ArmComponent(canbus::CANSocket& can_socket) : damiao_motor::DMDeviceCollection(can_socket) {} -void ArmComponent::init_motor_devices(std::vector motor_types, - std::vector send_can_ids, - std::vector recv_can_ids, bool use_fd) { +void ArmComponent::init_motor_devices(const std::vector& motor_types, + const std::vector& send_can_ids, + const std::vector& recv_can_ids, bool use_fd) { // Reserve space to prevent vector reallocation that would invalidate motor // references motors_.reserve(motor_types.size()); diff --git a/src/openarm/can/socket/openarm.cpp b/src/openarm/can/socket/openarm.cpp index f99eafd..9a0f342 100644 --- a/src/openarm/can/socket/openarm.cpp +++ b/src/openarm/can/socket/openarm.cpp @@ -73,6 +73,12 @@ void OpenArm::refresh_all() { } } +void OpenArm::refresh_one(int i) { + for (damiao_motor::DMDeviceCollection* device_collection : sub_dm_device_collections_) { + device_collection->refresh_one(i); + } +} + void OpenArm::disable_all() { for (damiao_motor::DMDeviceCollection* device_collection : sub_dm_device_collections_) { device_collection->disable_all(); diff --git a/src/openarm/damiao_motor/dm_motor_device_collection.cpp b/src/openarm/damiao_motor/dm_motor_device_collection.cpp index f8c6206..3ec8e05 100644 --- a/src/openarm/damiao_motor/dm_motor_device_collection.cpp +++ b/src/openarm/damiao_motor/dm_motor_device_collection.cpp @@ -41,6 +41,12 @@ void DMDeviceCollection::disable_all() { } } +void DMDeviceCollection::set_zero(int i) { + auto dm_device = get_dm_devices().at(i); + auto zero_packet = CanPacketEncoder::create_set_zero_command(dm_device->get_motor()); + send_command_to_device(dm_device, zero_packet); +} + void DMDeviceCollection::set_zero_all() { for (auto dm_device : get_dm_devices()) { CANPacket zero_packet = CanPacketEncoder::create_set_zero_command(dm_device->get_motor()); @@ -114,6 +120,8 @@ std::vector DMDeviceCollection::get_motors() const { return motors; } +Motor DMDeviceCollection::get_motor(int i) const { return get_dm_devices().at(i)->get_motor(); } + std::vector> DMDeviceCollection::get_dm_devices() const { std::vector> dm_devices; for (const auto& [id, device] : device_collection_->get_devices()) {