Add additional methods for low level single motor control (#22)
This PR adds the ability to refresh and query specific motors. The current use case is primarily for calibration.
This commit is contained in:
parent
4478a105d8
commit
ebfbf010c8
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
@ -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
|
||||||
@ -27,9 +27,9 @@ public:
|
|||||||
ArmComponent(canbus::CANSocket& can_socket);
|
ArmComponent(canbus::CANSocket& can_socket);
|
||||||
~ArmComponent() = default;
|
~ArmComponent() = default;
|
||||||
|
|
||||||
void init_motor_devices(std::vector<damiao_motor::MotorType> motor_types,
|
void init_motor_devices(const std::vector<damiao_motor::MotorType>& motor_types,
|
||||||
std::vector<uint32_t> send_can_ids, std::vector<uint32_t> recv_can_ids,
|
const std::vector<uint32_t>& send_can_ids,
|
||||||
bool use_fd);
|
const std::vector<uint32_t>& recv_can_ids, bool use_fd);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<damiao_motor::Motor> motors_;
|
std::vector<damiao_motor::Motor> motors_;
|
||||||
|
|||||||
@ -48,6 +48,8 @@ public:
|
|||||||
void disable_all();
|
void disable_all();
|
||||||
void set_zero_all();
|
void set_zero_all();
|
||||||
void refresh_all();
|
void refresh_all();
|
||||||
|
|
||||||
|
void refresh_one(int i);
|
||||||
// The timeout for reading from socket, set to timeout_us.
|
// The timeout for reading from socket, set to timeout_us.
|
||||||
// Tuning this value may improve the performance but should be done with caution.
|
// Tuning this value may improve the performance but should be done with caution.
|
||||||
void recv_all(int timeout_us = 500);
|
void recv_all(int timeout_us = 500);
|
||||||
|
|||||||
@ -32,9 +32,12 @@ public:
|
|||||||
// Common motor operations
|
// Common motor operations
|
||||||
void enable_all();
|
void enable_all();
|
||||||
void disable_all();
|
void disable_all();
|
||||||
void set_zero_all();
|
|
||||||
void set_callback_mode_all(CallbackMode callback_mode);
|
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)
|
// Refresh operations (for individual motors)
|
||||||
void refresh_one(int i);
|
void refresh_one(int i);
|
||||||
void refresh_all();
|
void refresh_all();
|
||||||
@ -49,6 +52,7 @@ public:
|
|||||||
|
|
||||||
// Device collection access
|
// Device collection access
|
||||||
std::vector<Motor> get_motors() const;
|
std::vector<Motor> get_motors() const;
|
||||||
|
Motor get_motor(int i) const;
|
||||||
canbus::CANDeviceCollection& get_device_collection() { return *device_collection_; }
|
canbus::CANDeviceCollection& get_device_collection() { return *device_collection_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -23,9 +23,9 @@ namespace openarm::can::socket {
|
|||||||
ArmComponent::ArmComponent(canbus::CANSocket& can_socket)
|
ArmComponent::ArmComponent(canbus::CANSocket& can_socket)
|
||||||
: damiao_motor::DMDeviceCollection(can_socket) {}
|
: damiao_motor::DMDeviceCollection(can_socket) {}
|
||||||
|
|
||||||
void ArmComponent::init_motor_devices(std::vector<damiao_motor::MotorType> motor_types,
|
void ArmComponent::init_motor_devices(const std::vector<damiao_motor::MotorType>& motor_types,
|
||||||
std::vector<canid_t> send_can_ids,
|
const std::vector<canid_t>& send_can_ids,
|
||||||
std::vector<canid_t> recv_can_ids, bool use_fd) {
|
const std::vector<canid_t>& recv_can_ids, bool use_fd) {
|
||||||
// Reserve space to prevent vector reallocation that would invalidate motor
|
// Reserve space to prevent vector reallocation that would invalidate motor
|
||||||
// references
|
// references
|
||||||
motors_.reserve(motor_types.size());
|
motors_.reserve(motor_types.size());
|
||||||
|
|||||||
@ -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() {
|
void OpenArm::disable_all() {
|
||||||
for (damiao_motor::DMDeviceCollection* device_collection : sub_dm_device_collections_) {
|
for (damiao_motor::DMDeviceCollection* device_collection : sub_dm_device_collections_) {
|
||||||
device_collection->disable_all();
|
device_collection->disable_all();
|
||||||
|
|||||||
@ -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() {
|
void DMDeviceCollection::set_zero_all() {
|
||||||
for (auto dm_device : get_dm_devices()) {
|
for (auto dm_device : get_dm_devices()) {
|
||||||
CANPacket zero_packet = CanPacketEncoder::create_set_zero_command(dm_device->get_motor());
|
CANPacket zero_packet = CanPacketEncoder::create_set_zero_command(dm_device->get_motor());
|
||||||
@ -114,6 +120,8 @@ std::vector<Motor> DMDeviceCollection::get_motors() const {
|
|||||||
return motors;
|
return motors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Motor DMDeviceCollection::get_motor(int i) const { return get_dm_devices().at(i)->get_motor(); }
|
||||||
|
|
||||||
std::vector<std::shared_ptr<DMCANDevice>> DMDeviceCollection::get_dm_devices() const {
|
std::vector<std::shared_ptr<DMCANDevice>> DMDeviceCollection::get_dm_devices() const {
|
||||||
std::vector<std::shared_ptr<DMCANDevice>> dm_devices;
|
std::vector<std::shared_ptr<DMCANDevice>> dm_devices;
|
||||||
for (const auto& [id, device] : device_collection_->get_devices()) {
|
for (const auto& [id, device] : device_collection_->get_devices()) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user