1. Setup: DLL Project, Control XDL & the AHAS Lua file Revision as of 20:06, 31 October 2012 by Alexalspach (Talk | contribs)
To implement your own control algorithm for the Allegro Hand is relatively simple once the intial framework has been established. This tutorial will guide you through the steps necessary to create you own controller plugin and access it via Allegro Application Studio.
Note: This tutorial assumes you have Allegro Application Studio and Visual Studio 2008 (Service Pack 1) installed. If you have not yet installed Allegro Application Studio, please see the pages Allegro Application Studio (Installation) and Allegro Application Studio (User Manual).
Contents |
Create User Controllers Folder
Start off by creating a folder called userControllers within the Allegro Hand installation directory. The Visual Studio projects can be stored anywhere, but if you match the project folder location seen in this tutorial, all following file paths specified will be correct.
Allegro Hand Application Studio\userControllers
Within this folder, we will create a new Visual Studio DLL project.
Create New DLL Project
Open up Visual Studio (VS) 2008. Again, it is necessary to have Service Pack 1 installed to use SimLab products.
Create Project
In the File dropdown menu, click New > Project.
''File'' > ''New'' > ''Project''
In the New Project window, select Win32 under Project types and choose the Win32 Console Application template. In the Name field, choose a name for the controller. It will be most convenient to match the tutorial and choose control_AllegroHand for the project name. In the Location field, choose the newly created userControllers folder in the Allegro Hand Application Studio directory.
C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\userControllers
Click OK to continue.
When greeted by the Win32 Application Wizard, click Next > to configure the new project.
You will then be presented with a few options. Change the Application type to DLL and, under Addition options, choose to create and Empty project.
Click Finish to create your new project.
Add Files
In the Solution Explorer (likely in a pane on the left side of VS) you should see your new project, control_AllegroHand. Right click the bold project name (not Solution 'control_AllegroHand' (1 project)) to add a new item to the project.
control_AllegroHand (right click) > Add > New Item...
If you click Visual C++ under in the Categories pane, you will all of the available templates. Choose the template C++ File (.cpp) and name is control_AllegroHand. Leave the location as the default. Click Add to add the file to your project.
Repeat the Add New Item process two more times to add two Header Files (.h) to the project titled control_AllegroHand and control_AllegroHandCmd.
By this time you should have added three files to the project:
control_AllegroHand.cpp control_AllegroHand.h control_AllegroHandCmd.h
You can see these new files in your Solution Explorer.
Project Properties
To compile the project with all the proper dependencies and behaviors, the several properties must be set prior.
In the Solution Explorer (likely in a pane on the left side of VS), right click the bold project name (not Solution 'control_AllegroHand' (1 project)), and select Properties.
control_AllegroHand (right click) > Properties
Within the project Property Pages window, you will see a pane of expandable groups. The following properties must be edited before compiling a control plugin for Allegro Hand Application Studio:
Configuration Properties > C/C++ > 1. General > Additional Include Directories: ..\..\..\include; 2. Preprocessor > Preprocessor Definitions: WIN32;_DEBUG;_WINDOWS;_USRDLL;CONTROL_ALLEGROHAND_EXPORTS;R_EXPORTS Configuration Properties > Linker > 3. General > Output File: ..\..\..\bin\controls\$(ProjectName).dll; 4. General > Additional Library Directories: ..\..\..\lib;..\..\..\lib\BHand; 5. Input > Additional Dependencies: rMath_9.lib rxControlSDK_9.lib libBHand.lib
The additional include directory added contains all of the header files installed with Allegro Application Studio.
The only new preprocessor definition should be R_EXPORTS. This allows the DLL file to be exported properly for use with Allegro Hand Application Studio.
The output file specified is the DLL file control plugin. This is output the the bin\controls directory where AHAS can access it. The additional library directories contain general and Allegro Hand specific libraries included with AHAS.
The additional dependencies include the RoboticsLab Math and Controls SDK libraries, along with the Allegro Hand library.
Press Apply to save the changes then press OK to close the Properties window.
Create Controller XDL
And XDL file must be created to link AHAS and the controller DLL exported by the VS project. This file has two main purposes:
- It provides the path to the controller DLL
- This allows the user to easily switch to a new controller by simply changing the path. Neither the controller file code nor the AHAS files need to be edited to switch the controller.
- Variables can be added to this file and accessed by the controller.
- This allows properties like gains to be edited without recompiling the controller code.
New XDL
For the purpose of separating user created control plugins from the stock AHAS controller, we will create a new XDL file to be used with a new AHAS file. For future user created controller plugins, you need only edit the path to the control plugin DLL within this XDL. You will not need to create a new XDL and AHAS file for each control plugin.
Start by navigating to the controls folder of your AHAS installation folder.
C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\controls
In this folder you will find a file entitled control_ERHand. Copy and paste this file within the same directory, controls, and rename it control_AllegroHand.
Edit with RoboticsLab
If you have SimLab's RoboticsLab software, you can edit the XDL file using rBuilder. When opened, you will see multiple entries on the left, including Name, the controller name, and Path, the path to the DLL file exported by our control_AllegroHand VS project. The fields currently say control_ERHand and control_ERHand.dll. Change the Name and Path fields to control_AllegroHand and control_AllegroHand.dll, respectively.
Reminder: The path is just the name of the DLL file because the DLL will export to the same folder as the XDL file, controls.
Last, we will check the field titles whichHand. This field is referenced by the controller to determine whether to control a left or right hand. If you are using an Allegro RIGHT Hand, this field should say Right. If using a LEFT hand, this field should say Left. Save the changes and close rBuilder.
Edit without RoboticsLab
If you do not have RoboticsLab, then you must edit the XDL text file directly. The contents of the file can be edited in any text editor but an editor meant for html editing, like Notepad++, is suggested.
Note: A 30-day free trial of RoboticsLab can be downloaded at http://www.simlab.co.kr/Download.htm
Open the XDL file in whatever text editor you choose and you will see the following.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <DLL xmlns="http://www.simlab.co.kr/2008/XDL" name="control_ERHand" path="control_ERHand.dll" type="USER_CONTROL" ver="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.simlab.co.kr/2008/XDL XDL.xsd"> <credit address="SimLab Co., Ltd." creator="Sangyup Yi" date="August 22, 2012" description="control Allegro Hand" email="seanyi@simlab.co.kr"/> <property name="whichHand" value="Right"/> </DLL>
In this XML code, the fields of interest are set apart from the rest of the code. In your XML file, there will likely be one long line with most of the information in it. In this XML file we must change the fields Name, the controller name, and Path, the path to the DLL file exported by our control_AllegroHand VS project. The fields currently say control_ERHand and control_ERHand.dll. Change the Name and Path fields to control_AllegroHand and control_AllegroHand.dll, respectively.
Reminder: The path is just the name of the DLL file because the DLL will export to the same folder as the XDL file, controls.
Last, we will check the field titled whichHand. This field is referenced by the controller to determine whether to control a left or right hand. If you are using an Allegro RIGHT Hand, this field should say Right. If using a LEFT hand, this field should say Left. The new file should read as follows:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <DLL xmlns="http://www.simlab.co.kr/2008/XDL" name="control_AllegroHand" path="control_AllegroHand.dll" type="USER_CONTROL" ver="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.simlab.co.kr/2008/XDL XDL.xsd"> <credit address="SimLab Co., Ltd." creator="Sangyup Yi" date="August 22, 2012" description="control Allegro Hand" email="seanyi@simlab.co.kr"/> <property name="whichHand" value="Left"/> </DLL>
Save the changes and close the text editor.
AHAS Lua File
dfdf
notes
DLL project sim or app not necessary, just plugin to AAS
- C/C++ GENERAL additional include (..\..\..\include;)
- Linker GENERAL output file to bin controls (..\..\..\bin\controls\$(ProjectName).dll)
- Linker geral addition lib dirs (..\..\..\lib;..\..\..\lib\BHand;)
- Linker input additonal dep (rMath_9.lib rxControlSDK_9.lib libBHand.lib)
- C/C++ Preprocessor Definitions WIN32;_DEBUG;_WINDOWS;_USRDLL;CONTROL_ALLEGROHAND_EXPORTS;R_EXPORTS
Create XDL path to DLL
Create Custom Lua file with new controller Add buttons, maybe
- create new project
- Win32 Application, DLL, empty proj
- Add cpp, h, and h
control_AllegroHandCmd.h:
#ifndef __CONTROL_ALLEGROHAND_AUTO_CMD_H__ #define __CONTROL_ALLEGROHAND_AUTO_CMD_H__ #include "rCommand/rCmdDefine.h" #define DEFAULT_CMD (RCMD_USER + 1) //#define USER_CMD_1 (RCMD_USER + 10) #endif
control_AllegroHand.h:
#ifndef __CONTROL_ALLEGROHAND_H__ #define __CONTROL_ALLEGROHAND_H__ #include <list> #include "rControlAlgorithm/rControlAlgorithm.h" #include "BHand/BHand.h" //#include "rDeviceERHandRemoteCmd.h" // for BlueTooth or TCPIP control #define JDOF 16 // Degrees of freedom class REXPORT control_AllegroHand : public rControlAlgorithmEx { public: control_AllegroHand(rDC rdc); ~control_AllegroHand(); virtual void init(int mode = 0); virtual void update(const rTime& t); //// dont use // virtual void setNominalSystem(const TCHAR* path, const TCHAR* aml, const HTransform& T0, const dVector& q0); //// dont use //virtual void setPeriod(const rTime& dT); virtual int command(const short& cmd, const int& arg = 0); //// for plotting // virtual void datanames(vector<string_type>& names, int channel = -1); // virtual void collect(vector<double>& data, int channel = -1); //// for Move Object?? for telling where to grasp // virtual void onSetInterestFrame(const TCHAR* name, const HTransform& T); private: // virtual void _estimate(); virtual void _readDevices(); virtual void _writeDevices(); //virtual void _reflect(); virtual void _compute(const rTime& t); void _arrangeJointDevices(); //void _servoOn(); //void _servoOff(); private: rTime _cur_time; BHand* _hand; bool _is_left_hand; rID _motor[16]; rID _enc[16]; //rID _remoteTP_BT; //rID _remoteTP_TCPIP; dVector _q; // joint position for 16 joints dVector _qdot; // joint velocity dVector _torque; // joint torque int _jdof; double _x[4]; double _y[4]; double _z[4]; //// for testing each motor //int _jid_test; //bool _test_mode; //// for remote control //MessageRemoteTP_t _msgRTP; //int _sz2read_msgRTP; //// for show off //int _demo_mode; //rTime _demo_start_time; //dVector _demo_q_des; }; #endif
control_AllegroHand.h:
#ifndef __CONTROL_ALLEGROHAND_H__ #define __CONTROL_ALLEGROHAND_H__ #include <list> #include "rControlAlgorithm/rControlAlgorithm.h" // make sure this header is in the Allegro Hand Application Studio include directory #include "BHand/BHand.h" #define JDOF 16 // Degrees of freedom class REXPORT control_AllegroHand : public rControlAlgorithmEx { public: control_AllegroHand(rDC rdc); ~control_AllegroHand(); virtual void init(int mode = 0); // controller will update every control period virtual void update(const rTime& t); // send motor commands virtual int command(const short& cmd, const int& arg = 0); private: virtual void _readDevices(); virtual void _writeDevices(); virtual void _compute(const rTime& t); // function will find all joint devices void _arrangeJointDevices(); private: rTime _cur_time; BHand* _hand; bool _is_left_hand; rID _motor[16]; // motor IDs rID _enc[16]; // encoder IDs dVector _q; // joint position for 16 joints (read from encoders) dVector _qdot; // joint velocity dVector _torque; // joint torque dVector _q_des // target joint position int _jdof; // number of degrees of freedom (16) double _x[4]; // X coord for each of the 4 fingertips double _y[4]; // Y coord for each of the 4 fingertips double _z[4]; // Z coord for each of the 4 fingertips }; #endif
Copyright & Trademark Notice
Allegro, the Allegro logo, RoboticsLab, the RoboticsLab logo, and all related files and documentation are Copyright ⓒ 2008-2020 Wonik Robotics Co., Ltd. All rights reserved. RoboticsLab and Allegro are trademarks of Wonik Robotics. All other trademarks or registered trademarks mentioned are the properties of their respective owners.
Wonik Robotics's Allegro Hand is based on licensed technology developed by the Humanoid Robot Hand research group at the Korea Institute of Industrial Technology (KITECH).
Any references to the BHand Library or the Allegro Hand Motion and/or Grasping Library refer to a library of humanoid robotic hand grasping algorithms and motions developed and published by KITECH researchers.
J.-H. Bae, S.-W. Park, D. Kim, M.-H. Baeg, and S.-R. Oh, "A Grasp Strategy with the Geometric Centroid of a Groped Object Shape Derived from Contact Spots," Proc. of the 2012 IEEE Int. Conf. on Robotics and Automation (ICRA2012), pp. 3798-3804
Wiki maintained by Sean Yi <seanyi@wonikrobotics.com>
Whos here now: Members 0 Guests 3 Bots & Crawlers 1 |