UCLV Dynamixel Utils
Loading...
Searching...
No Matches
motor.hpp
1#pragma once
2
3#include "dynamixel_sdk/dynamixel_sdk.h"
4#include "colors.hpp"
5#include <string>
6
7namespace uclv::dynamixel_utils
8{
9
13 class Motor
14 {
15 private:
16 uint8_t id_;
17 std::string serial_port_;
18 int baudrate_;
19 float protocol_version_;
20
21 uint16_t addrTargetPosition_ = 30;
22 uint16_t addrPresentPosition_ = 36;
23
24 uint16_t addrTorqueEnable_ = 24;
25
26 uint16_t lenAddrTargetPosition_ = 2;
27 uint16_t lenAddrPresentPosition_ = 2;
28
29 dynamixel::PortHandler *portHandler_;
30 dynamixel::PacketHandler *packetHandler_;
31
32 public:
43 Motor(const std::string &serial_port, int baudrate, float protocol_version,
44 dynamixel::PortHandler *const &portHandler, dynamixel::PacketHandler *const &packetHandler,
45 uint8_t id);
46
55 Motor(const std::string &serial_port, int baudrate, float protocol_version,
56 uint8_t id);
57
61 Motor();
62
63 // DISTRUTTORE?
64
70 void setId(uint8_t id);
71
77 uint8_t getId();
78
84 void setAddrTargetPosition(uint16_t addrTargetPosition);
85
91 uint16_t getAddrTargetPosition() const;
92
98 void setAddrPresentPosition(uint16_t addrPresentPosition);
99
105 uint16_t getAddrPresentPosition() const;
106
112 void setLenAddrTargetPosition(uint16_t lenAddrTargetPosition);
113
119 uint16_t getLenAddrTargetPosition() const;
120
126 void setLenAddrPresentPosition(uint16_t lenAddrPresentPosition);
127
133 uint16_t getLenAddrPresentPosition() const;
134
135 void setAddrTorqueEnable(uint16_t addrTorqueEnable);
136
137 uint16_t getAddrTorqueEnable() const;
138
144 void setTargetPosition(float position);
145
151 uint16_t readPresentPosition();
152
160 void write1OnAddress(uint8_t id, uint16_t address, uint8_t data);
161
169 void write2OnAddress(uint8_t id, uint16_t address, uint16_t data);
170
178 uint8_t read1FromAddress(uint8_t id, uint16_t address);
179
187 uint16_t read2FromAddress(uint8_t id, uint16_t address);
188
196 bool enableTorque();
197
205 bool disableTorque();
206 };
207}
The Motor class represents a single motor connected to the system.
Definition motor.hpp:14
void write1OnAddress(uint8_t id, uint16_t address, uint8_t data)
Writes a byte to the specified address of the motor.
Definition motor.cpp:194
uint16_t getAddrPresentPosition() const
Gets the address for the present position.
Definition motor.cpp:116
uint8_t getId()
Gets the identifier of the motor.
Definition motor.cpp:80
bool enableTorque()
Enables torque for the motor.
Definition motor.cpp:270
uint16_t getAddrTargetPosition() const
Gets the address for the target position.
Definition motor.cpp:98
void setLenAddrPresentPosition(uint16_t lenAddrPresentPosition)
Sets the size (nr of bytes to write) for address of the present position.
Definition motor.cpp:143
void setLenAddrTargetPosition(uint16_t lenAddrTargetPosition)
Sets the size (nr of bytes to write) for address of the target position.
Definition motor.cpp:125
uint8_t read1FromAddress(uint8_t id, uint16_t address)
Reads a byte from the specified address of the motor.
Definition motor.cpp:230
void setAddrTargetPosition(uint16_t addrTargetPosition)
Sets the address for the target position.
Definition motor.cpp:89
uint16_t getLenAddrTargetPosition() const
Gets the size (nr of bytes to write) for address of the target position.
Definition motor.cpp:134
void write2OnAddress(uint8_t id, uint16_t address, uint16_t data)
Writes two bytes to the specified address of the motor.
Definition motor.cpp:212
void setTargetPosition(float position)
Sets the target position of the motor.
Definition motor.cpp:173
bool disableTorque()
Disables torque for the motor.
Definition motor.cpp:290
uint16_t readPresentPosition()
Reads the present position of the motor.
Definition motor.cpp:183
void setId(uint8_t id)
Sets the identifier of the motor.
Definition motor.cpp:71
uint16_t read2FromAddress(uint8_t id, uint16_t address)
Reads two bytes from the specified address of the motor.
Definition motor.cpp:250
void setAddrPresentPosition(uint16_t addrPresentPosition)
Sets the address for the present position.
Definition motor.cpp:107
uint16_t getLenAddrPresentPosition() const
Gets the size (nr of bytes to write) for address of the present position.
Definition motor.cpp:152
Motor()
Default constructor.
Definition motor.cpp:57