Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bc3eee2
servo model Xm430w350 added
Mar 19, 2019
16f1829
some function with bulk_read and sync_write added (XM,MX,XL models)
Mar 19, 2019
024c520
Xm430w350 added in auto_detect
Mar 19, 2019
29154d5
bulk_read and sync_write fully implemented for protocol 1 and 2
Mar 19, 2019
f2f33c0
.waf delete
Mar 19, 2019
2ea4a5d
get_speed with bulk_read implemented for MX,XM,XL models
Mar 20, 2019
27f1c4c
bulk_write for protocol 2 only added
Mar 26, 2019
78cd3e8
sync_read for protocol 2 only added
Mar 26, 2019
f81be4c
baudrate list updated, operating mode list updated
Mar 26, 2019
703aea1
minor update - some control mode added and baudrate table updated
Apr 1, 2019
52e16f7
restore and rename the new version of set_goal_positions
dogoepp Apr 2, 2019
ca8b2a5
use angle version of set_goal_positions
dogoepp Apr 6, 2019
380319a
Add two error types for vector sizes
dogoepp Apr 6, 2019
5a7d828
'echo value' changed (4ms -> 0ms)
PedroDesRobots Jun 14, 2019
8c147a0
add bulk_read sync_write function with model abstraction - IN PROGRESS
Jun 14, 2019
d368bc6
Merge branch 'dev' of https://github.com/resibots/libdynamixel into dev
Jun 14, 2019
fe7cea4
add bulk_speed sync_speed with model abstraction
Jun 14, 2019
9ddd037
operating mode update - PWM/Voltage and multi_turn_torque
Jun 17, 2019
53f6b7a
command line for bulk and sync added
Jun 17, 2019
cb2ce1b
text updated
PedroDesRobots Jun 17, 2019
3ef3b74
usb2dynamixel fixed
Jun 17, 2019
455882e
Merge branch 'dev' of https://github.com/resibots/libdynamixel into dev
Jun 17, 2019
58ccb5d
comment case EWOULDBLOCK
Jun 17, 2019
77e6a06
conflict solve
Jun 17, 2019
db4d14f
update utility and servo with model abstraction method
Jun 18, 2019
fc8bf4c
Merge pull request #62 from resibots/dev-dogoepp
PedroDesRobots Jun 18, 2019
7299f69
delete HEAD comment
Jun 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you want your USB2AX serial interface to appear in `/dev` as `usb2axN` (where

If the reading time seems too long, check the value of the USB latency timer. On ubuntu this value is retrieved with this command `cat /sys/bus/usb-serial/devices/ttyUSB0/latency_timer`. It is the time, in milliseconds, for which the device driver buffers data before making it available.

You can change this timer with the command `echo 4 | sudo tee /sys/bus/usb-serial/devices/ttyUSB0/latency_timer` which sets it to 4 ms for the device `/dev/ttyUSB0`.
You can change this timer with the command `echo 0 | sudo tee /sys/bus/usb-serial/devices/ttyUSB0/latency_timer` which sets it to 0 ms for the device `/dev/ttyUSB0`.

## Using Libdynamixel on Mac

Expand Down
10 changes: 8 additions & 2 deletions src/demos/operating_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#include <dynamixel/dynamixel.hpp>

#include <iostream>
#include <string.h>
#include <string>
#include <iostream>

using namespace dynamixel;
using namespace servos;
Expand All @@ -26,6 +26,12 @@ std::string string_operating_mode(Usb2Dynamixel& controller, typename Protocol::
case OperatingMode::multi_turn:
str_mode = "multi-turn";
break;
case OperatingMode::multi_turn_torque:
str_mode = "multi-turn-torque";
break;
case OperatingMode::PWM:
str_mode = "PWM";
break;
default:
str_mode = "unknown";
}
Expand Down Expand Up @@ -87,4 +93,4 @@ int main(int argc, char** argv)
}

return 0;
}
}
1 change: 0 additions & 1 deletion src/demos/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

def build(bld):
bld(features='cxx cxxprogram', source='dynamixel_simple_check.cpp', target="dynamixel_simple_check", includes=". ..")
bld(features='cxx cxxprogram', source='dynamixel_test.cpp', target="dynamixel_test", includes=". ..")
bld(features='cxx cxxprogram', source='omnipointer_arm.cpp', target="omnipointer_arm", includes=". ..")
bld(features='cxx cxxprogram', source='operating_mode.cpp', target="operating_mode", includes=". ..")
4 changes: 3 additions & 1 deletion src/dynamixel/auto_detect.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DYNAMIXEL_AUTO_DETECT_HPP_
#define DYNAMIXEL_AUTO_DETECT_HPP_

#include <memory>
#include <map>
#include <memory>

#include "errors/error.hpp"
#include "servos.hpp"
Expand Down Expand Up @@ -35,6 +35,8 @@ namespace dynamixel {
inline std::shared_ptr<servos::BaseServo<protocols::Protocol2>> get_servo(protocols::Protocol2::id_t id, uint16_t model, protocols::Protocol2::address_t selected_protocol)
{
switch (model) {
case servos::Xm430W350::ct_t::model_number_value:
return std::make_shared<servos::Xm430W350>(id);
case servos::Xl320::ct_t::model_number_value:
return std::make_shared<servos::Xl320>(id);
case servos::ProL4210S300::ct_t::model_number_value:
Expand Down
12 changes: 9 additions & 3 deletions src/dynamixel/baudrate.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef DYNAMIXEL_BAUDRATE_HPP_
#define DYNAMIXEL_BAUDRATE_HPP_

#include <stdint.h>
#include <memory>
#include <stdint.h>

#include "protocols.hpp"
#include "errors/error.hpp"
#include "protocols.hpp"

namespace dynamixel {
/** The template specifications of this method are used to set the baudrate
Expand Down Expand Up @@ -45,6 +45,12 @@ namespace dynamixel {
return 3;
case 1000000:
return 1;
case 2250000:
return 250;
case 2500000:
return 251;
case 3000000:
return 252;
default:
std::stringstream err_message;
err_message << "Invalid baudrate for protocol 1: " << baudrate;
Expand Down Expand Up @@ -80,6 +86,6 @@ namespace dynamixel {
throw errors::Error(err_message.str());
}
}
}
} // namespace dynamixel

#endif
40 changes: 21 additions & 19 deletions src/dynamixel/controllers/usb2dynamixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ namespace dynamixel {
@param error number, usually the value of errno
@return std::string of the explanation
**/
std::string write_error_string(int error_number)
inline std::string write_error_string(int error_number)
{
switch (error_number) {
case EAGAIN:
return "EAGAIN: The file descriptor fd refers to a file other than "
"a socket and has been marked nonblocking (O_NONBLOCK), and "
"the write would block.";
// On some OS, EWOULDBLOCK has the same value as EAGAIN and would hence not compile.
// case EWOULDBLOCK:
// return "EWOULDBLOCK: The file descriptor fd refers to a socket "
// "and has been marked nonblocking (O_NONBLOCK), and the "
// "write would block.";
// On some OS, EWOULDBLOCK has the same value as EAGAIN and would hence not compile.
#ifdef __APPLE__
case EWOULDBLOCK:
return "EWOULDBLOCK: The file descriptor fd refers to a socket "
"and has been marked nonblocking (O_NONBLOCK), and the "
"write would block.";
#endif
case EBADF:
return "EBADF: fd is not a valid file descriptor or is not open for writing.";
case EDESTADDRREQ:
Expand Down Expand Up @@ -147,10 +149,10 @@ namespace dynamixel {

const int ret = write(_fd, packet.data(), packet.size());

// std::cout << "Send: ";
// for (size_t i = 0; i < packet.size(); ++i)
// std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)packet[i] << " ";
// std::cout << std::endl;
// std::cout << "Send: ";
// for (size_t i = 0; i < packet.size(); ++i)
// std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)packet[i] << " ";
// std::cout << std::endl;

if (ret == -1) {
throw errors::Error("Usb2Dynamixel::Send write error " + write_error_string(errno));
Expand Down Expand Up @@ -178,23 +180,23 @@ namespace dynamixel {
std::vector<uint8_t> packet;
packet.reserve(_recv_buffer_size);

// std::cout << "Receive:" << std::endl;
// std::cout << "Receive:" << std::endl;

do {
double current_time = get_time();
uint8_t byte;
int res = read(_fd, &byte, 1);
if (res > 0) {
// std::cout << std::setfill('0') << std::setw(2)
// << std::hex << (unsigned int)byte << " ";
// std::cout << std::setfill('0') << std::setw(2)
// << std::hex << (unsigned int)byte << " ";
packet.push_back(byte);

state = status.decode_packet(packet, _report_bad_packet);
if (state == DecodeState::INVALID) {
// std::cout << "\tBad packet: ";
// for (const auto byte : packet)
// std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)byte << " ";
// std::cout << std::endl;
// std::cout << "\tBad packet: ";
// for (const auto byte : packet)
// std::cout << std::setfill('0') << std::setw(2) << std::hex << (unsigned int)byte << " ";
// std::cout << std::endl;

packet.clear();
}
Expand All @@ -206,8 +208,8 @@ namespace dynamixel {
return false;
} while (state != DecodeState::DONE);

// std::cout << std::endl;
// std::cout << std::dec;
// std::cout << std::endl;
// std::cout << std::dec;

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/dynamixel/errors/bad_packet.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DYNAMIXEL_BAD_PACKET_ERROR_HPP_
#define DYNAMIXEL_BAD_PACKET_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down Expand Up @@ -39,7 +39,7 @@ namespace dynamixel {
private:
const std::vector<uint8_t> _packet;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
11 changes: 6 additions & 5 deletions src/dynamixel/errors/crc_error.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#ifndef DYNAMIXEL_ERRORS_CRC_ERROR_HPP_
#define DYNAMIXEL_ERRORS_CRC_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <sstream>
#include <stdint.h>
#include <string>

#include "error.hpp"

namespace dynamixel {
namespace errors {
class CrcError : public Error {
public:
CrcError(uint8_t id, uint8_t protocol, uint32_t expected, uint32_t received) : _id(id), _protocol(protocol), _expected(expected), _received(received)
CrcError(uint8_t id, uint8_t protocol, uint32_t expected, uint32_t received)
: _id(id), _protocol(protocol), _expected(expected), _received(received)
{
std::stringstream err_message;
err_message << "Status: checksum error while decoding packet with ID " << (int)id;
Expand Down Expand Up @@ -44,7 +45,7 @@ namespace dynamixel {
uint8_t _id, _protocol;
uint32_t _expected, _received;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
4 changes: 2 additions & 2 deletions src/dynamixel/errors/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ namespace dynamixel {
{
return err.print(os);
}
}
}
} // namespace errors
} // namespace dynamixel

#define CHECK(val, msg) check(__FILE__, __LINE__, (val), msg)
#endif
8 changes: 4 additions & 4 deletions src/dynamixel/errors/servo_limit_error.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef DYNAMIXEL_ERRORS_SERVO_LIMIT_ERROR_HPP_
#define DYNAMIXEL_ERRORS_SERVO_LIMIT_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <sstream>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down Expand Up @@ -46,7 +46,7 @@ namespace dynamixel {
int _id;
double _max, _min, _value;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
6 changes: 3 additions & 3 deletions src/dynamixel/errors/status_error.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef DYNAMIXEL_STATUS_ERROR_HPP_
#define DYNAMIXEL_STATUS_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down Expand Up @@ -38,7 +38,7 @@ namespace dynamixel {
private:
uint8_t _id, _protocol, _error_byte;
};
}
}
} // namespace errors
} // namespace dynamixel

#endif
4 changes: 2 additions & 2 deletions src/dynamixel/errors/unpack_error.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef DYNAMIXEL_ERRORS_UNPACK_ERROR_HPP_
#define DYNAMIXEL_ERRORS_UNPACK_ERROR_HPP_

#include <string>
#include <stdint.h>
#include <sstream>
#include <stdint.h>
#include <string>

#include "error.hpp"

Expand Down
55 changes: 55 additions & 0 deletions src/dynamixel/errors/vector_size_errors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef DYNAMIXEL_VECTOR_SIZE_ERROR_HPP_
#define DYNAMIXEL_VECTOR_SIZE_ERROR_HPP_

#include <string>

#include "error.hpp"

namespace dynamixel {
namespace errors {
class VectorEmptyError : public Error {
public:
VectorEmptyError(const std::string& method_name,
const std::string& vector_name)
: _method_name(method_name), _vector_name(vector_name)
{
this->_msg = "The vector " + vector_name + ", passed to "
+ method_name + " cannot be empty (size 0)";
}

std::string vector_name() const
{
return _vector_name;
}

std::string method_name() const
{
return _method_name;
}

protected:
const std::string _method_name, _vector_name;
};

class VectorSizesDifferError : public Error {
public:
VectorSizesDifferError(const std::string& method_name,
const std::string& name1, const std::string& name2)
: _method_name(method_name)
{
this->_msg = "The vectors " + name1 + " and " + name2
+ ", passed to " + method_name + " should have the same size.";
}

std::string method_name() const
{
return _method_name;
}

protected:
const std::string _method_name;
};
} // namespace errors
} // namespace dynamixel

#endif
Loading