Go to the documentation of this file.
36 #include "std_msgs/String.h"
37 #include "dynamixel_sdk_examples/SyncGetPosition.h"
38 #include "dynamixel_sdk_examples/SyncSetPosition.h"
44 #define ADDR_TORQUE_ENABLE 64
45 #define ADDR_PRESENT_POSITION 132
46 #define ADDR_GOAL_POSITION 116
47 #define ADDR_INDIRECT_ADDR1 168
48 #define ADDR_INDIRECT_ADDR5 176
49 #define ADDR_INDIRECT_DATA1 224
50 #define ADDR_INDIRECT_DATA5 228
53 #define PROTOCOL_VERSION 2.0 // Default Protocol version of DYNAMIXEL X series.
56 #define DXL1_ID 1 // DXL1 ID
57 #define DXL2_ID 2 // DXL2 ID
58 #define BAUDRATE 57600 // Default Baudrate of DYNAMIXEL X series
59 #define DEVICE_NAME "/dev/ttyUSB0" // [Linux] To find assigned port, use "$ ls /dev/ttyUSB*" command
68 dynamixel_sdk_examples::SyncGetPosition::Request & req,
69 dynamixel_sdk_examples::SyncGetPosition::Response & res)
71 uint8_t dxl_error = 0;
73 int dxl_addparam_result =
false;
76 int32_t position1 = 0;
77 int32_t position2 = 0;
82 if (dxl_addparam_result !=
true) {
83 ROS_ERROR(
"Failed to addparam to groupSyncRead for Dynamixel ID %d", req.id1);
88 if (dxl_addparam_result !=
true) {
89 ROS_ERROR(
"Failed to addparam to groupSyncRead for Dynamixel ID %d", req.id2);
97 ROS_INFO(
"getPosition : [POSITION:%d]", position1);
98 ROS_INFO(
"getPosition : [POSITION:%d]", position2);
99 res.position1 = position1;
100 res.position2 = position2;
104 ROS_ERROR(
"Failed to get position! Result: %d", dxl_comm_result);
112 uint8_t dxl_error = 0;
114 int dxl_addparam_result =
false;
115 uint8_t param_goal_position1[4];
116 uint8_t param_goal_position2[4];
119 uint32_t position1 = (
unsigned int)msg->position1;
124 uint32_t position2 = (
unsigned int)msg->position2;
133 if (dxl_addparam_result !=
true) {
134 ROS_ERROR(
"Failed to addparam to groupSyncWrite for Dynamixel ID %d", msg->id1);
138 if (dxl_addparam_result !=
true) {
139 ROS_ERROR(
"Failed to addparam to groupSyncWrite for Dynamixel ID %d", msg->id2);
144 ROS_INFO(
"setPosition : [ID:%d] [POSITION:%d]", msg->id1, msg->position1);
145 ROS_INFO(
"setPosition : [ID:%d] [POSITION:%d]", msg->id2, msg->position2);
147 ROS_ERROR(
"Failed to set position! Result: %d", dxl_comm_result);
153 int main(
int argc,
char ** argv)
155 uint8_t dxl_error = 0;
164 ROS_ERROR(
"Failed to set the baudrate!");
169 for (uint8_t i = 0; i < 4; i++) {
213 ros::init(argc, argv,
"indirect_address_node");
#define ADDR_INDIRECT_ADDR1
bool addParam(uint8_t id)
void syncSetPositionCallback(const dynamixel_sdk_examples::SyncSetPosition::ConstPtr &msg)
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
#define ADDR_PRESENT_POSITION
virtual bool setBaudRate(const int baudrate)=0
int main(int argc, char **argv)
ServiceServer advertiseService(AdvertiseServiceOptions &ops)
PacketHandler * packetHandler
bool syncGetPresentPositionCallback(dynamixel_sdk_examples::SyncGetPosition::Request &req, dynamixel_sdk_examples::SyncGetPosition::Response &res)
bool addParam(uint8_t id, uint8_t *data)
#define ADDR_INDIRECT_DATA5
PortHandler * portHandler
static PacketHandler * getPacketHandler(float protocol_version=2.0)
static PortHandler * getPortHandler(const char *port_name)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
virtual bool openPort()=0
virtual int write1ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint8_t data, uint8_t *error=0)=0
GroupSyncWrite groupSyncWrite(portHandler, packetHandler, ADDR_INDIRECT_DATA5, 4)
#define ADDR_TORQUE_ENABLE
GroupSyncRead groupSyncRead(portHandler, packetHandler, ADDR_INDIRECT_DATA1, 4)
#define ADDR_INDIRECT_ADDR5
#define ADDR_GOAL_POSITION
#define ADDR_INDIRECT_DATA1
uint32_t getData(uint8_t id, uint16_t address, uint16_t data_length)
virtual void closePort()=0
virtual int write2ByteTxRx(PortHandler *port, uint8_t id, uint16_t address, uint16_t data, uint8_t *error=0)=0