In the last few tutorials, we 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

Let's open up myAHController.lua and take a look.
This is the file that we made in Tutorial 1 which links to out new controller.
The function OnGUI() is the area of interest. This function contains the buttons we seen on the AHAS GUI.
To create a button and link its press to a command is as simple as follows:

...
	-- ROW 1
	row = 1
	col = 1
	button_image = Image.new("buttonImages/home_off.png")
	if (isHome) then
		button_image = Image.new("buttonImages/home_on.png")
	end
    if (GUI.Button(Rect.new(button(row,col)[1], button(row,col)[2], button(row,col)[3], button(row,col)[4]),  button_image)) then	
		controller:command(RCMD_GO_HOME, VK_H)
		print("Home button pressed")
		allMotionsFalse()
		if (isConnected) then isHome = true end
	end
...

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

The function controller:command() is used to forward a command to the hand controller, the DLL plug-in, myAHController.dll.

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

myAHControllerCmd.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 __MY_AH_CONTROLLER_CMD_H__
#define __MY_AH_CONTROLLER_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

myAHController.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 myAHController::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 myAHController::_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 myAHController.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, myAHControllerCmd.h.


myAHController.lua

...
 
  BH_READY 			= RCMD_USER + 2
  BH_GRASP_3 		= RCMD_USER + 3
  BH_GRASP_4 		= RCMD_USER + 4
  BH_PINCH_IT 		= RCMD_USER + 5
  BH_PINCH_MT 		= RCMD_USER + 6
  BH_ENVELOP 		= RCMD_USER + 8
  BH_SHOWOFF 		= RCMD_USER + 50
  BH_GRAVITY_COMP 	= RCMD_USER + 9
  BH_TEST 			= RCMD_USER + 100
 
  CAN_CMD_RESET_ENC = 4
 
  function OnGUI()
 
...


Please note that the command, BH_READY, is defined above as RCMD_USER + 2.
This is the same as feeding RCMD_USER + 2 directly into controller:command(). 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 myAHControllerCmd.h header file definitions. We will then add the code to be executed with each button to myAHController.cpp's command() function.

myAHControllerCmd.h:

...
 
#define BH_NONE		(RCMD_USER + 0)
#define BH_HOME		(RCMD_GO_HOME)
#define BH_READY		(RCMD_USER + 2)
#define BH_GRASP_3	(RCMD_USER + 3)
#define BH_GRASP_4	(RCMD_USER + 4)
#define BH_PINCH_IT	(RCMD_USER + 5)
#define BH_PINCH_MT	(RCMD_USER + 6)
#define BH_ENVELOP	(RCMD_USER + 8)
 
//#define BH_MORE	(RCMD_USER + 99)
 
...

myAHConroller.cpp

myAHController::myAHController(rDC rdc) 
:rControlAlgorithmEx(rdc)
, _jdof(0)                              // everything is NULL to start
, _hand(NULL)
, _is_left_hand(false)
, _demo_mode(false)		  // will be used when
, _demo_start_time(0)	          // we make our own motion
{
}
 
...
int myAHController::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:    // The position ensures that all joints are oriented properly for executing a grasp.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_HOME);
		}
		break;
	case BH_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 BH_GRASP_3:  // This grasping algorithm is a torque-controlled, three-fingered grip. 
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_GRASP_3);
		}
		break;
	case BH_GRASP_4:  // This grasping algorithm is a torque-controlled, four-fingered grip. 
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_GRASP_4);
		}
		break;
	case BH_PINCH_IT: // This grasping algorithm is a torque-controlled, two-fingered pinch.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_PINCH_IT);
		}
		break;
	case BH_PINCH_MT: // This grasping algorithm is a torque-controlled, two-fingered pinch.
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_PINCH_MT);
		}
		break;
	case BH_ENVELOP: // This grasping algorithm is a torque-controlled, two-fingered pinch.
		{
			_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 myAHController.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 myAHController.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.

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.


myAHController.lua

...
  function Update()
  	-- Can be used do draw graphic elements in AHAS
  end
 
  BH_READY 			= RCMD_USER + 2
  BH_GRASP_3 		= RCMD_USER + 3
  BH_GRASP_4 		= RCMD_USER + 4
  BH_PINCH_IT 		= RCMD_USER + 5
  BH_PINCH_MT 		= RCMD_USER + 6
  BH_ENVELOP 		= RCMD_USER + 8
--  BH_SHOWOFF 		= RCMD_USER + 50
  BH_DEMO1			= RCMD_USER + 50
  BH_GRAVITY_COMP 	= RCMD_USER + 9
  BH_TEST 			= RCMD_USER + 100
 
...
 
  function allMotionsFalse()
    isHome = false
    isReady = false
    isGrasp3 = false
    isGrasp4 = false
    isPinchIT = false
    isPinchMT = false
    isEnvelop = false
--    isShowOff = false
	isOn = false
    isGravity = false
  end
 
...
 
	row = 4
	col = 2	
	button_image = Image.new("buttonImages/off.png")
	if (isOn) then
		button_image = Image.new("buttonImages/on.png")
	end  
	if (GUI.Button(Rect.new(button(row,col)[1], button(row,col)[2], button(row,col)[3], button(row,col)[4]),  button_image)) then	
		controller:command(BH_DEMO1)
		print("Demo1 button pressed")
		allMotionsFalse()
		if (isConnected) then isOn = true end			
	end	
 
...

myAHControllerCmd.h

...
 
#define BH_ENVELOP	(RCMD_USER + 8)
#define BH_DEMO1		(RCMD_USER + 50)
 
#endif

myAHController.cpp

int myAHController::command(const short& cmd, const int& arg)
...
 
	case BH_ENVELOP:
		{
			_demo_mode = 0;
			if (_hand)
				_hand->SetMotionType(eMotionType_ENVELOP);
		}
		break;
	case BH_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!
Please move on to the next tutorial.

5. Joint PD Control Without Hand Library





Add your comment
Allegro Hand welcomes all comments. If you do not want to be anonymous, register or log in. It is free.




Copyright & Trademark Notice
Allegro, the Allegro logo, RoboticsLab, the RoboticsLab logo, and all related files and documentation are Copyright ⓒ 2008-2016 WONIK ROBOTICS. 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.

SimLab'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 1