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.

...
 
-- "HandController", name assigned to controller plugin control_AllegroHand.dll (linked through control_AllegroHand.xdl)
-- code from function Awake()
   -- createController("HandController", "hand") --, 1, "controls/control_AllegroHand.xdl", "")
   -- setControlAlgorithm("HandController", "controls/control_AllegroHand.xdl")
 
-- RCMD_GO_HOME, command value recognized by switch statement within control_AllegroHand.cpp's command() function.
-- RCMD_GO_HOME defined in control_AllegroHandCmd.h
 
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 AH_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 AH_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 AH_ONE).

#ifndef __CONTROL_ALLEGROHAND_CMD_H__
#define __CONTROL_ALLEGROHAND_CMD_H__
 
#include "rCommand/rCmdManipulator.h"
 
// These command values 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.
 
// RCMD_GO_HOME and RCMD_USER are predefines
// Every user command besides the 'home' command
// will be RCMD_USER plus an integer
 
#define AH_NONE		(RCMD_USER + 0)
#define AH_HOME		(RCMD_GO_HOME)
// #define AH_ONE       (RCMD_USER + 1)
 
#endif

control_AllegroHand.cpp

Now that the 'home' command, AH_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. The 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.

Here is the button code in the LUA file:

...
 
    -- 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, VK_R)
    end
    if (GUIButton(5, 65, 120, 25, "GRASP 3")) then
      sendCommand("HandController", RCMD_USER + 3, VK_G)
    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, VK_P)
    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
 
...


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. 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.

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




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