HerkuleXLib  1.2
Arduino library to drive HerkuleX DRS-0101 and DRS-0201
HerkuleXLib documentation

Table of Contents

Limitations

Please consider the following comments to use the library:

*The printout mode displays send/receive data and errors through the Serial Monitor on the computer

Inspiration

This work was inspired by the code from Alessandro Giacomel proposed here: http://robottini.altervista.org/dongbu-herkulex-arduino-library-2. The software serial option was not considered because it is limited to a baud rate of 57600 bps that generates some communication problems to feedback informations from the servos to the Arduino card.

Quick start

Wiring

The wiring of the servo with an Arduino MEGA (on Serial1 port) is sketched and photographed below.

wiring_herkulex_arduino.png
Wiring sketch of the HerkuleX with Arduino MEGA
photo_wiring.jpg
Wiring photo of the HerkuleX with Arduino MEGA

Installation of the library

Download the last version of the library from: http://www.benoitpuel.com/blog/...zip

For the first install, open Arduino software and add the library as described here: https://www.arduino.cc/en/Guide/Libraries#toc4. In a nutshell, go to menu Sketch > Include Library > Add .ZIP library, then select the library from your download folder.

To update the library, you need first to remove the previous version. For that, open Arduino software and an example from this library (menu File > Examples > HerkuleXLib > MyFirstHerkuleXLib_MEGA). Then open the directory in the file manager (menu Sketch > Show sketch folder). Go up 3 level in the file tree in the folder called "libraries" and delete the folder called "HerkuleXLib". Then close Arduino software, reopen it (to refresh its alvailable libraries) and install the last version of the library as for a first installation.

Your first program

The following example is proposed for the case of Arduino MEGA (see Wiring).

For writing your first Arduino program using the HerkuleXLib library, first open Arduino software and create a new file (menu File > New). Save it (menu File > Save) as "MyFirstHerkuleXLib_MEGA". Include the library to the project (menu Sketch > Include library > HerkuleX). You should get the following code:

#include <HkxPosControl.h>
#include <HkxSetup.h>
#include <HkxStatus.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

Even if all the headers are not necessary, lets keep them all to avoid errors. Let's now create the instances for the printout, the communication and the control position for one servo.

...
void setup() {
HkxPrint printout = HkxPrint(Serial, 9600); // Printout errors on the serial monitor
HkxCommunication communication = HkxCommunication(HKX_115200, Serial1, printout); // Communication with the servo on Serial1
HkxPosControl servo(253, communication, printout); // control position for the servo ID=253 (factory default value)
}
...

The servo has its LED and torque off (torque off means that you can turn the servo manually).

To turn the LED to red colour, add the following lines (more details here: HkxPosControl.setTorqueLEDControl()).

servo.setTorqueLEDControl(HKX_NO_VALUE, HKX_LED_RED); // set the LED to red
Serial.println(F("--> LED is now red"));
delay(10000); // wait 10 seconds

And I guess you bought this servo and install this library for one main purpose: moving the servo! The code below will execute the move and change the color of the LED to blue for the servo moving period only (more details here: HkxPosControl.movePosition()).

Serial.println(F("--> Move to 45 degrees in 2 seconds, blue LED"));
servo.movePosition(450, 2000, HKX_LED_BLUE, true); // set the servo to 45° in 2 seconds, led turns to blue during the move
Serial.println(F("--> Move is finished, torque is free and LED back to red"));

One nice feature of this servo is that you can get some feedback measures. For instance, you can read the input voltage (voltage of the battery if powered with a battery) and the current position (more details here: HkxPosControl.getBehaviour()).

uint16_t inputVoltage;
int16_t position;
// get the current behaviour of the servo
servo.getBehaviour(&inputVoltage, HKX_NO_VALUE, &position, HKX_NO_VALUE, HKX_NO_VALUE, HKX_NO_VALUE, HKX_NO_VALUE, HKX_NO_VALUE);
Serial.print(F("--> Input voltage is:"));
Serial.println((float)inputVoltage/1000);
Serial.print(F("--> Current position (degree) is:"));
Serial.println((float)position/10);

You can now compile and transfer the program, open the serial monitor and you should see the following display.

serial_monitor.png
Serial monitor while executing MyFirstHerkuleXLib_MEGA

You can find this code from the menu File > Examples > HerkuleXLib > MyFirstHerkuleXLib_MEGA

The same example is available for Arduino UNO in the menu File > Examples > HerkuleXLib > MyFirstHerkuleXLib_UNO. As said in Limitations, there no possible printout to serial monitor with the Arduino UNO.

Realise notes

v1.0

First realise

v1.1

v1.2

License

This project is released under the GNU GPL V3 (see http://www.gnu.org/licenses/gpl-3.0.en.html).

Author

Email: conta.nosp@m.ct@b.nosp@m.enoit.nosp@m.puel.nosp@m..com
Web: http://www.benoitpuel.com
Author: Benoit Puel