ROBOTIS-GIT / Dynamixel2Arduino

DYNAMIXEL protocol library for Arduino
Apache License 2.0
87 stars 55 forks source link

Custom Port Handlers and other minor suggestions #72

Closed KurtE closed 2 months ago

KurtE commented 3 years ago

I am starting to play again with Dynamixel servos, and am in the process of trying to convert using some code that uses my version of the old Bioloid library (https://github.com/kurte/bioloidserial) to a current Robotis Servo library. And I wish to have this work on both OpenCM/OpenCR as well as with some other processors, in particular with Teensy boards (PJRC) such as the T4.1.

As per previous discussions, at least at the time, non-Arduino/Robotis brand hardware changes were not supported in other libraries such as the Dynamixel SDK library so working with this library now.

Some simple suggestions for this library.

a) https://emanual.robotis.com/ - Under the Software tab should include a link to this library. The only place you find details is if you go to the https://emanual.robotis.com/docs/en/parts/interface/dynamixel_shield/ page...

b) To use with Teensy boards, In most cases I will probably need to use a Custom Port handler. So started playing with example. Suggestion: Change private to protected... That is:

class SerialPortHandler : public DXLPortHandler
{
  public:
    SerialPortHandler(HardwareSerial& port, const int dir_pin = -1);

    virtual void begin() override;
    virtual void end() override;
    virtual int available(void) override;
    virtual int read() override;
    virtual size_t write(uint8_t) override;
    virtual size_t write(uint8_t *buf, size_t len) override;

    virtual void begin(unsigned long baud);
    virtual unsigned long getBaud() const;

  protected:
    HardwareSerial& port_;
    const int dir_pin_;
    unsigned long baud_;
};

Then your example sketch does not have to replicate both the port_ and dirpin variables. That is you would not need those two variables defined in your NewSerialPortHandler, nor would your constructor have to set them.

c) still wish at times that the port handler write functions had a way to say this completes my data or not. That way you don't have to buffer up all of the data into some secondary buffer, just to do one write, to minimize how many times you set/clear the IO pin and or do flush operations.

d) Wish that there were some of the ControlTableItem data that was public and not private. That is suppose I want to setup code that uses SyncWrite to output the GOAL_POSITION for the servos. Sometimes I will be building for a Hex robot that uses AX servos (Protocol 1). Sometimes I will build for XL-430 servos (Protocol 2). Right now I have to do my own detect of servo type and have my own information for which register it is and the length of it...

Sorry I know that this is more than one thing... But thought I would mention all of this now which I was thinking about it.

Kurt

ROBOTIS-Will commented 3 years ago

Hi @KurtE

Thank you for your meaningful suggestions that can expand the use of D2A library. Please expect some delays on reviewing and working on this as my team is preparing some other incoming updates for other project. We should be able to start working on this from mid-September, but please feel free to create a PR, and @ROBOTIS-David will test the changes and merge for the next release.

We may need to discuss more about some of these items later for thorough understanding of use case. Thank you!