(AHAS Shortcut)
(AHAS Shortcut)
 
(9 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
This tutorial assumes you have completed both of the previous tutorials, [[1. Setup: DLL Project, Control XDL & the AHAS Lua file]] and [[2. Allegro Hand Joint Position Control]]. Also, this tutorial assumes that you have one of the four stock supported CAN devices
 
This tutorial assumes you have completed both of the previous tutorials, [[1. Setup: DLL Project, Control XDL & the AHAS Lua file]] and [[2. Allegro Hand Joint Position Control]]. Also, this tutorial assumes that you have one of the four stock supported CAN devices
 
  
 
==AHAS Lua File==
 
==AHAS Lua File==
  
Navigate to the Allegro Hand Application Studio (AHAS) controls directory and locate the file called ''ERHAND_NI-CAN_LEFT''.
+
Navigate to the Allegro Hand Application Studio (AHAS) controls directory and locate the file called AHAS_NI-CAN_L.lua.
  
 
<pre>C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\controls</pre>
 
<pre>C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\controls</pre>
  
Find the Lua file called ''ERHAND_NI-CAN_LEFT.lua'' and copy it to your Desktop. Rename the file ''ALLEGROHAND1_ACTUAL.lua''. Open ''ALLEGROHAND1_ACTUAL.lua'' to see the following code.
+
Find the Lua file called AHAS_NI-CAN_L.lua and copy it to your Desktop. Rename the file ''myAHController_ACTUAL.lua''. Open ''myAHController_ACTUAL.lua'' to see the following code.
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function Awake()
+
  print(RoboticsLab.version())
print("Begin Allegro Hand")
+
version()
+
  aml = "models/Etc/AllegroHand/AllegroHandL_RT_NICAN.aml"
 +
  controlXDL = "controls/control_AHAS_L.xdl"
 +
 +
  rtTimer = Timer.new("RTTimer", rTimer_MODE_REAL_WIN32)
 +
  sysname = "RTSys"
 +
  T0 = HTransform.new(Rotation.new(), Vector3D.new(0, 0, 0))
 +
  hand = RoboticsLab.createRTSystem(aml, sysname, T0, rtTimer)
  
-- If you just want to simulate, comment "rtTimer" and "createRTSystem"
+
  comm = hand:findDevice("COMM")
-- and uncomment loadModel
+
  print(comm)
-- to change CAN interface, change "createRTSystem" line
+
 
+
  step = 1
--loadModel("hand", "models/Etc/ERHand/ERHand.aml")
+
  deltaT = 0.003
rtTimer = createTimer("RTTimer", rTimer_MODE_REAL_WIN32)
+
  controller = RoboticsLab.createController("controller", hand, step)
print(rtTimer)
+
  controller:setAlgorithm(controlXDL)
createRTSystem("models/Etc/ERHand/ERHandL_RT_NICAN.aml", "RTSys", rtTimer)
+
  controller:setPeriod(deltaT)
createController("RTController", "RTSys") --, 1, "controls/control_ERHand.xdl", "")
+
  controller:setNominalSystem(aml, sysname)--, T0)  
setControlAlgorithm("RTController", "controls/control_ERHandL.xdl")
+
   
--setNominalSystem("HandController", "")
+
  end
+
 
+
 
   function Update()
 
   function Update()
   -- body
+
   -- Can be used do draw graphic elements in AHAS
  end
+
 
+
BH_READY = RCMD_USER + 2
+
CAN_CMD_RESET_ENC = 4
+
 
+
 
+
  function OnGUI()
+
   
+
    if (GUIButton(5, 5, 120, 25, "On")) then
+
      onDevice("RTSys", "COMM")
+
      sendCommand("RTController", RESERVED_CMD_SERVO_ON)
+
    end
+
   
+
    if (GUIButton(130, 5, 120, 25, "Off")) then
+
      --offDevice("RTSys", "COMM")
+
      --sendCommand("RTController", RESERVED_CMD_SERVO_OFF)
+
  sendCommand("RTController", RCMD_USER + 0)
+
  print("None")
+
    end
+
   
+
  if (GUIButton(5, 35, 120, 25, "Home")) then
+
  sendCommand("RTController", RCMD_GO_HOME, VK_H)
+
  print("Home button pressed")
+
  end
+
  if (GUIButton(130, 35, 120, 25, "Ready")) then
+
  sendCommand("RTController", BH_READY, VK_R)
+
  print("Ready button pressed")
+
  end
+
 
+
    if (GUIButton(5, 65, 120, 25, "GRASP 3")) then
+
  sendCommand("RTController", RCMD_USER + 3, VK_G)
+
  print("Grasp 3 button pressed")
+
  end
+
    if (GUIButton(130, 65, 120, 25, "GRASP 4")) then
+
      sendCommand("RTController", RCMD_USER + 4)
+
    end
+
 
+
  if (GUIButton(5, 95, 120, 25, "PINCHING(I)")) then
+
  sendCommand("RTController", RCMD_USER + 5, VK_P)
+
  print("Pinching button pressed")
+
  end
+
    if (GUIButton(130, 95, 120, 25, "PINCHING(M)")) then
+
      sendCommand("RTController", RCMD_USER + 6)
+
    end
+
 
+
    if (GUIButton(5, 125, 245, 25, "Envelop")) then
+
      sendCommand("RTController", RCMD_USER + 8)
+
      print("Envelop")
+
    end
+
+
    if (GUIButton(5, 155, 245, 25, "Show Off")) then
+
      sendCommand("RTController", RCMD_USER + 50)
+
      print("Show Off")
+
    end
+
 
+
 
+
if (GUIButton(5, 185, 120, 25, "Test Encoders")) then
+
 
+
  for i=1,16 do
+
encName = "enc"..i
+
+
if i == 1 then
+
print(" ")
+
print("Finger 1")
+
end
+
+
if i == 5 then
+
print(" ")
+
print("Finger 2")
+
end
+
+
if i == 9 then
+
print(" ")
+
print("Finger 3")
+
end
+
+
if i == 13 then
+
print(" ")
+
print("Finger 4")
+
end
+
+
deviceCommand("RTSys", encName, CAN_CMD_RESET_ENC)
+
--print("Test Encoders")
+
  end
+
 
+
    end
+
+
if (GUIButton(130, 185, 120, 25, "Test Motors")) then
+
      sendCommand("RTController", RCMD_USER + 99)
+
      print("Test Motors")
+
    end
+
+
+
    width = (ScreenWidth-10)/4
+
    --print(width)
+
    top = ScreenHeight - 35*5;
+
 
+
 
+
    for i=1,4 do
+
      for j=1,4 do
+
        context = "Finger"..i.."_Link"..j
+
        pos = jointPosition("RTSys", context)
+
        context=context..string.format(": %.3f",math.deg(pos))
+
        GUILabel(10 + (i-1)*width, top + 35*(j-1), width-10, 15, context)
+
        GUISlider(10 + (i-1)*width, top+ 15 + 35*(j-1), width-10, 16, math.deg(pos), -180, 180)
+
      end
+
    end
+
 
+
 
+
 
   end
 
   end
 +
...
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The line below loads the NI-CAN interfacing Allegro Hand model. We must change this to reflect the hand (left/right) and the CAN interface (NI/Softing/ESD/Kvaser) that are using. Please refer to the following table to determine with what model you must replace ''"ERHandL_RT_NICAN.aml"''.
+
The line below loads the NI-CAN interfacing Allegro Hand model. We must change this to reflect the hand (left/right) and the CAN interface (NI/Softing/ESD/Kvaser) that are using. Please refer to the following table to determine with what model you must replace ''"AllegroHand_RT_NICAN.aml"''.
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
createRTSystem("models/Etc/ERHand/ERHandL_RT_NICAN.aml", "RTSys", rtTimer)
+
  aml = "models/Etc/AllegroHand/AllegroHandL_RT_NICAN.aml"
 +
  rtTimer = Timer.new("RTTimer", rTimer_MODE_REAL_WIN32)
 +
  sysname = "RTSys"
 +
  hand = RoboticsLab.createRTSystem(aml, sysname, T0, rtTimer)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 159: Line 56:
 
|-
 
|-
 
| style="padding: 3px 5px 3px 5px; background: #F0F0F0" | <h5>Right</h5>
 
| style="padding: 3px 5px 3px 5px; background: #F0F0F0" | <h5>Right</h5>
| style="padding: 3px 5px 3px 5px" | ERHand_RT_NICAN.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHand_RT_NICAN.aml
| style="padding: 3px 5px 3px 5px" | ERHand_RT_SOFTING.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHand_RT_SoftingCAN.aml
| style="padding: 3px 5px 3px 5px" | ERHand_RT_KvaserCAN.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHand_RT_KvaserCAN.aml
| style="padding: 3px 5px 3px 5px" | ERHand_RT_ESDCAN.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHand_RT_ESDCAN.aml
 
|-
 
|-
 
| style="padding: 3px 5px 3px 5px; background: #F0F0F0" | <h5>Left</h5>
 
| style="padding: 3px 5px 3px 5px; background: #F0F0F0" | <h5>Left</h5>
| style="padding: 3px 5px 3px 5px" | ERHandL_RT_NICAN.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHandL_RT_NICAN.aml
| style="padding: 3px 5px 3px 5px" | ERHandL_RT_SOFTING.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHandL_RT_SoftingCAN.aml
| style="padding: 3px 5px 3px 5px" | ERHandL_RT_KvaserCAN.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHandL_RT_KvaserCAN.aml
| style="padding: 3px 5px 3px 5px" | ERHandL_RT_ESDCAN.aml
+
| style="padding: 3px 5px 3px 5px" | AllegroHandL_RT_ESDCAN.aml
 
|-
 
|-
 
|}
 
|}
 
+
<br>
For this tutorial, I am using NI can and a left Allegro Hand so I will leave this line as-is.
+
For this tutorial, I am using NI Can and a left Allegro Hand so I will leave this line as-is.<br>
 
+
Next we must link this new LUA file to the ''myAHController.xdl'' we made in tutorial 1.
Next we must link this new LUA file to the ''control_AllegroHand.xdl'' we made in tutorial 1.
+
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
createController("RTController", "RTSys") --, 1, "controls/control_ERHand.xdl", "")
+
  controlXDL = "controls/control_AHAS_L.xdl"
setControlAlgorithm("RTController", "controls/control_ERHandL.xdl")
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
These two lines must be changed to the following so that the AHAS can evoke our new controller.
+
This line must be changed to the following so that the AHAS can evoke our new controller.
  
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
createController("RTController", "RTSys") --, 1, "controls/control_AllegroHand.xdl", "")
+
  controlXDL = "controls/myAHController.xdl"
setControlAlgorithm("RTController", "controls/control_AllegroHandL.xdl")
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now move the file ''ALLEGROHAND1_ACTUAL.lua'' from the ''Desktop'' back into the ''controls'' directory.
+
Now move the file ''myAHController_ACTUAL.lua'' from the ''Desktop'' back into the ''controls'' directory.
  
 
==AHAS Shortcut==
 
==AHAS Shortcut==
Line 195: Line 89:
  
 
<pre>
 
<pre>
Original Target: "C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\Allegro.exe" controls\ALLEGROHAND1.lua   
+
Original Target: "C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\Allegro.exe" controls\myAHController.lua   
New Target:      "C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\Allegro.exe" controls\ALLEGROHAND1_ACTUAL.lua   
+
New Target:      "C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\Allegro.exe" controls\myAHController_ACTUAL.lua   
 
</pre>
 
</pre>
  
Line 203: Line 97:
 
'''''Note:''' Make sure to straighten out all of the fingers prior to running AHAS.''
 
'''''Note:''' Make sure to straighten out all of the fingers prior to running AHAS.''
  
Double-click the the shortcut to test it out. An Allegro Hand simulator should load with more buttons that before. Click ''On'' and the controller will immediately start controlling the actual Allegro Hand joints with the same sinusoidal patterns as the virtual. The AHAS model will reflect the joint movements of the actual hand.
+
Double-click the the shortcut to test it out. An Allegro Hand simulator should load with more buttons that before. Click ''On'' and the controller will immediately start controlling the actual Allegro Hand joints with the same sinusoidal patterns as the virtual. The AHAS model will reflect the joint movements of the actual hand.<br>
 +
If the hand motion is not correct, please check the dml is set properly.
  
 
Please move on to the next tutorial to learn how to use the AHAS button to evoke BHand library grasping motions and your own motions/algorithms.
 
Please move on to the next tutorial to learn how to use the AHAS button to evoke BHand library grasping motions and your own motions/algorithms.
  
[[4. Allegro Application Studio Buttons and Bhand Motions]]
+
[[4. AHAS Buttons and BHand Library Motions]]
 +
[[Category:Programming Guides]]

Latest revision as of 15:47, 30 April 2015

In the last tutorial, 2. Allegro Hand Joint Position Control, we developed a controller that commands the joints in a sinusoidal fashion. While any motion can be established at this point, we will show this same motion in the actual Allegro Hand to demonstrate the ease of developing a controller for use with both the virtual and actual Allegro Hand systems.

This tutorial assumes you have completed both of the previous tutorials, 1. Setup: DLL Project, Control XDL & the AHAS Lua file and 2. Allegro Hand Joint Position Control. Also, this tutorial assumes that you have one of the four stock supported CAN devices

Contents

[edit] AHAS Lua File

Navigate to the Allegro Hand Application Studio (AHAS) controls directory and locate the file called AHAS_NI-CAN_L.lua.

C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\controls

Find the Lua file called AHAS_NI-CAN_L.lua and copy it to your Desktop. Rename the file myAHController_ACTUAL.lua. Open myAHController_ACTUAL.lua to see the following code.

  print(RoboticsLab.version())
 
  aml = "models/Etc/AllegroHand/AllegroHandL_RT_NICAN.aml"
  controlXDL = "controls/control_AHAS_L.xdl"
 
  rtTimer = Timer.new("RTTimer", rTimer_MODE_REAL_WIN32)
  sysname = "RTSys"
  T0 = HTransform.new(Rotation.new(), Vector3D.new(0, 0, 0))
  hand = RoboticsLab.createRTSystem(aml, sysname, T0, rtTimer)
 
  comm = hand:findDevice("COMM")
  print(comm)
 
  step = 1
  deltaT = 0.003
  controller = RoboticsLab.createController("controller", hand, step)
  controller:setAlgorithm(controlXDL)
  controller:setPeriod(deltaT)
  controller:setNominalSystem(aml, sysname)--, T0) 
 
  function Update()
  	-- Can be used do draw graphic elements in AHAS
  end
 ...

The line below loads the NI-CAN interfacing Allegro Hand model. We must change this to reflect the hand (left/right) and the CAN interface (NI/Softing/ESD/Kvaser) that are using. Please refer to the following table to determine with what model you must replace "AllegroHand_RT_NICAN.aml".

  aml = "models/Etc/AllegroHand/AllegroHandL_RT_NICAN.aml"
  rtTimer = Timer.new("RTTimer", rTimer_MODE_REAL_WIN32)
  sysname = "RTSys"
  hand = RoboticsLab.createRTSystem(aml, sysname, T0, rtTimer)
NI CAN
Softing
Kvaser
ESD
Right
AllegroHand_RT_NICAN.aml AllegroHand_RT_SoftingCAN.aml AllegroHand_RT_KvaserCAN.aml AllegroHand_RT_ESDCAN.aml
Left
AllegroHandL_RT_NICAN.aml AllegroHandL_RT_SoftingCAN.aml AllegroHandL_RT_KvaserCAN.aml AllegroHandL_RT_ESDCAN.aml


For this tutorial, I am using NI Can and a left Allegro Hand so I will leave this line as-is.
Next we must link this new LUA file to the myAHController.xdl we made in tutorial 1.

  controlXDL = "controls/control_AHAS_L.xdl"

This line must be changed to the following so that the AHAS can evoke our new controller.

  controlXDL = "controls/myAHController.xdl"

Now move the file myAHController_ACTUAL.lua from the Desktop back into the controls directory.

[edit] AHAS Shortcut

Make a copy of the AHAS shortcut on the Desktop created in tutorial 1. Right click the shortcut and click Properties. Change the target as follows:

Original Target: "C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\Allegro.exe" controls\myAHController.lua  
New Target:      "C:\Program Files (x86)\SimLab\Allegro Hand Application Studio\bin\Allegro.exe" controls\myAHController_ACTUAL.lua  

Close the Properties window. Connect the Allegro Hand to your computer's CAN interface and turn it on.

Note: Make sure to straighten out all of the fingers prior to running AHAS.

Double-click the the shortcut to test it out. An Allegro Hand simulator should load with more buttons that before. Click On and the controller will immediately start controlling the actual Allegro Hand joints with the same sinusoidal patterns as the virtual. The AHAS model will reflect the joint movements of the actual hand.
If the hand motion is not correct, please check the dml is set properly.

Please move on to the next tutorial to learn how to use the AHAS button to evoke BHand library grasping motions and your own motions/algorithms.

4. AHAS Buttons and BHand Library Motions





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