UCLV Dynamixel Utils
Loading...
Searching...
No Matches
hand.hpp
1#pragma once
2
3#include <iostream>
4#include <vector>
5#include <string>
6#include <memory>
7#include <cmath>
8
9#include "dynamixel_sdk/dynamixel_sdk.h"
10
11#include "colors.hpp"
12
13#include "motor.hpp"
14#include "fingermotor.hpp"
15#include "wristmotor.hpp"
16
17namespace uclv::dynamixel_utils
18{
19
23 class Hand
24 {
25 private:
26 std::string serial_port_;
27 int baudrate_;
28 float protocol_version_;
29
30 dynamixel::PortHandler *portHandler_;
31 dynamixel::PacketHandler *packetHandler_;
32
33 std::vector<std::shared_ptr<FingerMotor>> fingerMotors_;
34 std::vector<std::shared_ptr<WristMotor>> wristMotors_;
35
36 std::unique_ptr<dynamixel::GroupSyncWrite> groupSyncWrite_ = nullptr;
37 std::unique_ptr<dynamixel::GroupSyncRead> groupSyncRead_ = nullptr;
38 std::unique_ptr<dynamixel::GroupBulkRead> groupBulkRead_ = nullptr;
39 std::unique_ptr<dynamixel::GroupBulkWrite> groupBulkWrite_ = nullptr;
40
41 public:
51 Hand(const std::string &serial_port, int baudrate, float protocol_version,
52 dynamixel::PortHandler *const &portHandler, dynamixel::PacketHandler *const &packetHandler);
53
61 Hand(const std::string &serial_port, int baudrate, float protocol_version);
62
66 Hand();
67
71 ~Hand();
72
76 bool initialize();
77
83 void setSerialPort(const std::string &serial_port);
84
90 void setBaudrate(int baudrate);
91
97 void setProtocolVersion(float protocol_version);
98
104 std::string getSerialPort();
105
111 int getBaudrate();
112
118 float getProtocolVersion();
119
125 void setPortHandler(dynamixel::PortHandler *portHandler);
126
132 void setPacketHandler(dynamixel::PacketHandler *packetHandler);
133
139 void setSerialPortLowLatency(const std::string &serial_port);
140
147 std::shared_ptr<FingerMotor> createFingerMotor(uint8_t id);
148
155 std::shared_ptr<WristMotor> createWristMotor(uint8_t id);
156
163 const std::vector<std::shared_ptr<FingerMotor>> &addFingerMotor(uint8_t id);
164
171 const std::vector<std::shared_ptr<WristMotor>> &addWristMotor(uint8_t id);
172
178 std::vector<std::shared_ptr<FingerMotor>> getFingerMotors();
179
185 std::vector<std::shared_ptr<WristMotor>> getWristMotors();
186
190 void printFingerMotors() const;
191
195 void printWristMotors() const;
196
202 void removeFingerMotor(uint8_t id);
203
209 void removeWristMotor(uint8_t id);
210
217 void moveFingerMotor(const uint8_t &id, const float &position);
218
225 void moveWristMotor(const uint8_t &id, const float &position);
226
233 uint16_t readFingerMotorPosition(const uint8_t &id);
234
241 uint16_t readWristMotorPosition(const uint8_t &id);
242
249 void moveMotors(const std::vector<uint8_t> &ids, const std::vector<float> &positions);
250
257 std::vector<uint32_t> readMotorsPositions(const std::vector<uint8_t> &ids);
258 };
259}
The Hand class represents a robotic hand with multiple motors.
Definition hand.hpp:24
std::vector< uint32_t > readMotorsPositions(const std::vector< uint8_t > &ids)
Reads the positions of multiple motors using bulk read.
Definition hand.cpp:576
void setSerialPort(const std::string &serial_port)
Sets the serial port.
Definition hand.cpp:96
bool initialize()
Initializes the hand.
Definition hand.cpp:63
std::vector< std::shared_ptr< WristMotor > > getWristMotors()
Gets the wrist motors.
Definition hand.cpp:200
void moveFingerMotor(const uint8_t &id, const float &position)
Moves a finger motor to a specified position.
Definition hand.cpp:384
uint16_t readWristMotorPosition(const uint8_t &id)
Reads the position of a wrist motor.
Definition hand.cpp:471
void removeFingerMotor(uint8_t id)
Removes a finger motor from the hand.
Definition hand.cpp:336
void moveMotors(const std::vector< uint8_t > &ids, const std::vector< float > &positions)
Moves multiple motors using bulk write.
Definition hand.cpp:501
void moveWristMotor(const uint8_t &id, const float &position)
Moves a wrist motor to a specified position.
Definition hand.cpp:413
void printFingerMotors() const
Prints the finger motors.
Definition hand.cpp:286
float getProtocolVersion()
Gets the protocol version.
Definition hand.cpp:146
~Hand()
Destructor.
Definition hand.cpp:54
void setProtocolVersion(float protocol_version)
Sets the protocol version.
Definition hand.cpp:116
void printWristMotors() const
Prints the wrist motors.
Definition hand.cpp:310
void setPortHandler(dynamixel::PortHandler *portHandler)
Sets the port handler.
Definition hand.cpp:156
std::shared_ptr< WristMotor > createWristMotor(uint8_t id)
Creates a wrist motor.
Definition hand.cpp:222
Hand()
Default constructor.
Definition hand.cpp:44
void setBaudrate(int baudrate)
Sets the baudrate.
Definition hand.cpp:106
std::string getSerialPort()
Gets the serial port.
Definition hand.cpp:126
int getBaudrate()
Gets the baudrate.
Definition hand.cpp:136
const std::vector< std::shared_ptr< FingerMotor > > & addFingerMotor(uint8_t id)
Adds a finger motor to the hand.
Definition hand.cpp:236
const std::vector< std::shared_ptr< WristMotor > > & addWristMotor(uint8_t id)
Adds a wrist motor to the hand.
Definition hand.cpp:263
void setSerialPortLowLatency(const std::string &serial_port)
Sets the serial port to low latency mode.
Definition hand.cpp:176
std::shared_ptr< FingerMotor > createFingerMotor(uint8_t id)
Creates a finger motor.
Definition hand.cpp:211
void setPacketHandler(dynamixel::PacketHandler *packetHandler)
Sets the packet handler.
Definition hand.cpp:166
uint16_t readFingerMotorPosition(const uint8_t &id)
Reads the position of a finger motor.
Definition hand.cpp:441
void removeWristMotor(uint8_t id)
Removes a wrist motor from the hand.
Definition hand.cpp:359
std::vector< std::shared_ptr< FingerMotor > > getFingerMotors()
Gets the finger motors.
Definition hand.cpp:190