In the last few tutorials, we verified created a control algorithm project and verified our setup by performing a simple user-defined motion on both the virtual and actual Allegro Hands. We did all this ignoring the features of Allegro Hand Application Studio (AHAS) as a robust GUI interface for controlling the hand and visualizing certain data.

In this tutorial, we will take advantage of buttons in AHAS and use them to invoke our own algorithms and those supplied along with AHAS in the BHand Library.

Contents

AHAS Buttons

In your AHAS bin/controls directory, locate the file ALLEGROHAND1.lua. This is the file that we made in Tutorial 1 which links to out new controller. Let's open up ALLEGROHAND1.lua and take a look.

The function OnGUI() is the area of interest. This function contains the buttons and joint angle sliders we seen on the AHAS GUI. To create a button and link its press to a command is as simple as follows:

...
 
    -- if button is pressed
    -- GUIButton(x-pos, y-pos, width, height, "name")
    if (GUIButton(5, 35, 120, 25, "Home")) then
 
      -- command to be send to controller:
      -- RCMD_GO_HOME, RCMD_GO_READY or RCMD_USER + #
      sendCommand("HandController", RCMD_GO_HOME, VK_H)
 
      -- command prompt output
      print("Home button pressed")
    end
 
...

This button, when pressed, will cause the hand to assume its Home position. As mentioned in the comments, the arguments of GUIButtons() specify the button's location and the string displayed on the button.

x-pos: button's distance from the left side of the AHAS window (pixels)
y-pos: button's distance from the top of the AHAS window (pixels)
width: button width (pixels)
height: button height (pixels)

The function sendCommand is used to forward a command to the hand controller, the DLL plug-in, control_AllegroHand.dll.

sendCommand("HandController", RCMD_GO_HOME)

Notice that all of the button code to command the Allegro Hand library motion is already available within the original LUA file, yet, if clicked, these buttons do nothing. We must develop the command() function in control_AllegroHand.cpp to handle the incoming commands.


Plug-in Command Handling

Since the buttons are already set up in AHAS, it is very easy to set up the function that will handle the commands in the control plug-in. But first, we must define the commands as integers for easy recognition.

control_AllegroHandCmd.h

In the following header file, the command BH_HOME, used to call the home position for the Allegro Hand, is defined as RCMD_GO_HOME. This represents an integer value predefined in rCmdManipulator.h.

The command BH_NONE is defined as RCMD_USER, another integer value predefined in rCmdDefine.h. We will use RCMD_USER plus some integer to define all of our further commands from both the BHand library and our user-written algorithms (see BH_ONE).

#ifndef __CONTROL_ALLEGROHAND_CMD_H__
#define __CONTROL_ALLEGROHAND_CMD_H__
 
#include "rCommand/rCmdManipulator.h"
 
// These commands will be fed into command()
// and can be used to envoke certain actions
// by the robot. Allegro Application Studio
// will use these to interface with the
// cotroller plug-in.
#define BH_NONE		(RCMD_USER + 0)
#define BH_HOME		(RCMD_GO_HOME)
// #define BH_ONE		(RCMD_USER + 1)
 
#endif

control_AllegroHand.cpp

Now that the 'home' command, BH_HOME has been defined, we can write the command handler into our controller. In the function command(), we will create a switch statement with the integer valued command as input. This method will allow us to easily expand out list off executable commands in the future.

int control_AllegroHand::command(const short& cmd, const int& arg)
{
	// Handles user-defined commands according to cmd.
	// Further information can be retrieved from the second argument.
 
	// The variable cmd will be received from Allegro Application Studio
	// and will be used to envoke hand actions
 
	switch (cmd)
	{
	case BH_HOME:
		{
			_demo_mode = 0;
 
			if (_hand)
				_hand->SetMotionType(eMotionType_HOME);
		}
		break;
 
	default:
		break;
	}
 
	return 0;
}

As you can see, when it is time to the home position, we must turn off demo mode, which, as you remember, is the sinusoidal joint position controller we implementer in the last two tutorials. But setting _demo_mode to zero will not do the trick. We must revisit the demo mode algorithm and edit the if statement around it.

Currently, the if statement controlling the execution of the demo mode algorithm is evaluated as always true. Replace the true with the variable _demo_mode so that we can once again control it. This will also prevent the algorithm from running immediately when AHAS starts up.

void control_AllegroHand::_compute(const double& t)
{
	if (_hand)
	{
		_hand->SetJointPosition(_q.array);		    // joint positions set via torque PID
 
                // DEMO MODE NOW ONLY RUNS IF WE SET _demo_mode TO 1
		if (_demo_mode) 
		{
			_hand->SetMotionType(eMotionType_JOINT_PD); // PID gains and motion control set
 
...

Compile then open up AHAS from the shortcut on your desktop.

Note: Make sure you are opening the shortcut that will run the virtual hand, not the actual hand.

The hand should be fully flat when AHAS starts. Click "Home" to send the home position command. That should assume the home position. Unfortunately, we now have no way to access our demo mode. We will fix that, but first, lets get all of the other buttons working.

More Buttons, More Motions

As you can see in the ALLEGROHAND1.lua code, all of the motion buttons already have a command in the form RCMD_USER + #. We will reference these commands to update our header file, control_AllegroHandCmd.h.


ALLEGROHAND1.lua

...
 
    -- RCMD_GO_HOME and RCMD_USER are predefines
    -- Every user command besides the 'home' command
    -- will be RCMD_USER plus an integer see the
    -- control_AllegroHandCmd.h header file for
    -- command definitions
    AH_READY = RCMD_USER + 2
 
...
 
    if (GUIButton(5, 35, 120, 25, "Home")) then
      sendCommand("HandController", RCMD_GO_HOME)
    end
    if (GUIButton(130, 35, 120, 25, "Ready")) then
      sendCommand("HandController", AH_READY)
    end
    if (GUIButton(5, 65, 120, 25, "GRASP 3")) then
      sendCommand("HandController", RCMD_USER + 3)
    end
    if (GUIButton(130, 65, 120, 25, "GRASP 4")) then
      sendCommand("HandController", RCMD_USER + 4)
    end
    if (GUIButton(5, 95, 120, 25, "PINCHING(I)")) then
      sendCommand("HandController", RCMD_USER + 5)
    end
    if (GUIButton(130, 95, 120, 25, "PINCHING(M)")) then
      sendCommand("HandController", RCMD_USER + 6)
    end
    if (GUIButton(5, 125, 245, 25, "Envelop")) then
      sendCommand("HandController", RCMD_USER + 8)
    end
 
...


Please note that the command, AH_READY, is defined above as RCMD_USER + 2. This is the same as feeding RCMD_USER + 2 directly into sendCommand(). Feel free to define these wherever you want.

According to the definitions in the AHAS LUA file, we will add these six (6) new commands to the control_AllegroHandCmd.h header file definitions. We will then add the code to be executed with each button to control_AllegroHand.cpp's command() function.


control_AllegroHandCmd.h:

...
 
#define AH_NONE		(RCMD_USER + 0)
#define AH_HOME		(RCMD_GO_HOME)
#define AH_READY	(RCMD_USER + 2)
#define AH_GRASP_3	(RCMD_USER + 3)
#define AH_GRASP_4	(RCMD_USER + 4)
#define AH_PINCH_IT	(RCMD_USER + 5)
#define AH_PINCH_MT	(RCMD_USER + 6)
#define AH_ENVELOP	(RCMD_USER + 8)
 
//#define AH_MORE	(RCMD_USER + 99)
 
...


control_AllegroHand.cpp

int control_AllegroHand::command(const short& cmd, const int& arg)
{
	// Handles user-defined commands according to cmd.
	// Further information can be retrieved from the second argument.
 
	// The variable cmd will be received from Allegro Application Studio
	// and will be used to envoke hand actions
 
	switch (cmd)
	{
	case AH_HOME:    // The position ensures that all joints are oriented properly for executing a grasp.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_HOME);
		}
		break;
	case AH_READY:   // Click the buttons entitled Ready to prepare for each type of grasping motion.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_READY);
		}
		break;
	case AH_GRASP_3:  // This grasping algorithm is a torque-controlled, three-fingered grip. 
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_GRASP_3);
		}
		break;
	case AH_GRASP_4:  // This grasping algorithm is a torque-controlled, four-fingered grip.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_GRASP_4);
		}
		break;
	case AH_PINCH_IT: // This grasping algorithm is a torque-controlled, two-fingered pinch.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_PINCH_IT);
		}
		break;
	case AH_PINCH_MT: // This grasping algorithm is a torque-controlled, two-fingered pinch.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_PINCH_MT);
		}
		break;
	case AH_ENVELOP:  // This grasping algorithm can be used to fully envelop an object within the hand's four fingers.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_ENVELOP);
		}
		break;
	default:
		break;
	}
 
	return 0;
}


As you can see in every case, we are ensuring that _demo_mode is set to zero. The value of the _demo_mode flag is checked every iteration. If _demo_mode == 1, then the demo code we wrote earlier will override the latest command.

Now compile, reload AHAS and play with your buttons!!


A Button Just For Us

In your AHAS bin/controls directory, locate the file ALLEGROHAND1.lua. Copy this file to your Desktop.

Note: Once again, we must copy this file to the desktop for editing then move it back to the controls folder when we are finished to avoid opening with admin privileges.

From the Desktop, let's open up ALLEGROHAND1.lua and take a look.


To make our own button we need only to copy the code from a stock button and change three things: the location, the name and the command sent to the controller.

First, select any of the stock button and copy the if statement and anything inside. Paste it below the last stock button (Envelop).

Now we will change a few things to make this button our own.


Name: The name of the button is the text displayed on the button within the AHAS GUI. I will name the new button "Demo Mode 1" but feel free to name this button whatever you'd like.
Position and Size: Defines the window position in pixels relative to the top left and the button size in pixels.

x-pos: button's distance from the left side of the AHAS window (pixels)
y-pos: button's distance from the top of the AHAS window (pixels)
width: button width (pixels)
height: button height (pixels)

Command: Command value to be send to the controller.


The following button code produces a button called "Demo Mode 1" just below the "Envelop" button. The command sent to the controller is RCMD_USER + 50. Remember, we will have to define this in the controller header for use in the controller command function.


ALLEGROHAND1.lua

...
 
    if (GUIButton(5, 125, 245, 25, "Envelop")) then
      sendCommand("HandController", RCMD_USER + 8)
    end
 
    if (GUIButton(5, 155, 245, 25, "Demo Mode 1")) then
      sendCommand("HandController", RCMD_USER + 50)
    end
 
...

controlAllegroHandCmd.h

...
 
#define AH_ENVELOP	(RCMD_USER + 8)
 
#define AH_DEMO1	(RCMD_USER + 50)
 
#endif


controlAllegroHand.cpp

int control_AllegroHand::command(const short& cmd, const int& arg)
...
 
	case AH_ENVELOP:
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_ENVELOP);
		}
		break;
	case AH_DEMO1:
		{
			_demo_mode = 1;
		}
		break;
	default:
		break;
	}
 
	return 0;
}


As simple as that!

With what you learned in this tutorial, you can add as many buttons and respective control algorithms as you want. Please feel free to share your results with us!


Actual Allegro Hand

The controller's command() function calls the BHand library functions and the command values used are based on the original LUA file. This means that the BHand library function like Grasp and Pinch should automatically work with the buttons in AHAS for the actual hand. These buttons send the same commands and will therefore execute the same motions without any changes to the LUA file.

If you would like to demonstrate your demo mode controller on the actual hand, you need only add your new button to ALLEGROHAND1_ACTUAL.lua.


Note: The first argument of sendCommand() is "RTController", not "HandController" as in the virtual hand LUA file.


ALLEGROHAND1_ACTUAL.lua

...
 
    if (GUIButton(5, 125, 245, 25, "Envelop")) then
      sendCommand("RTController", RCMD_USER + 8)
    end
 
    if (GUIButton(5, 155, 245, 25, "Demo Mode 1")) then
      sendCommand("RTController", RCMD_USER + 50)
    end
 
...






You are not allowed to post comments.




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>

KitechLogo.jpg Wonikrobotics logo.png





Whos here now:   Members 0   Guests 0   Bots & Crawlers 2