Tutorials

How To Program Hubo

How To Program Hubo


Part 3: How to Program Gestures

How to program gestures on Hubo KHR4

This tutorial assumes that you are familiar with the following:

-          C/C++ programming

-          VS6

-          Excell

This tutorial also assumes that you have already completed the following tutorials:

-          How to Program Hubo Part 1: The Basics

By the end of this tutorial one should be able to do the following

-          Design and build custom upper body animations

-          Safely move/command all of Hubo’s upper body parts

-          Verify functionality of animation before use on physical Hubo

Definitions:

T = Total time for event in increments of 10ms

UpperMovement[N] = Commands desired angle for given upper body joint N

FTN_half_1_cos(magnitude, time, start_time, duration, 0,0,&result1[0]) = Makes a smooth profile for a joint to follow instead of a step input.

-          Magnitude = max value/ending value of function.  Default 1 or -1 depending on desired direction

-          Time = time as defined in the loop.  Default time = time

-          Start_time = starting time in 10ms increments

-          Duration = how long it takes to reach the maximum value in 10ms increments

-          Do not change “0,0”

-          &result1[0] = stores the calculated profile in result1[0]

Joint Definitions “ UpperMovement[N] = “angle” where N = one of the three letter definitions below:

-          0 = Torso Yaw = XXX

-          1 = Head Yaw = XXX

-          2 = Head Pitch = XXX

-          3 = Left Shoulder Pitch = LSP

-          4 = Left Shoulder Yaw = LSY

-          5 = Left Shoulder Roll = LSR

-          6 = Left Elbow Bend = LEB

-          7 = Left Wrist Pitch = LWP

-          8 = Left Wrist Roll = LWR

-          9 = Right Shoulder Pitch = RSP

-          10 = Right Shoulder Yaw = RSY

-          11 = Right Shoulder Roll = RSR

-          12 = Right Elbow Bend = REB

-          13 = Right Wrist Roll = RWR

-          14 = Right Wrist Pitch = RWP

 

Getting to the gesture code:

1.       Open HUBO2.dsw

 

2.       Go to Resource View

 

3.       Double open IDD_DIALOG_GESTURE

 

4.       Double click on the button you want to edit.  In this example we will be editing BLANK_2

 

5.       You will now be in the potion of the code that controls the functionality of the button.  In this case we are dealing with Button 31.  Here it is important that you note what motion number.  In this case MotionNo = 29.  Also note the line T =900.  This means that the total time of this motion will last 900 cycles where each cycle is 10ms.  Thus this motion will last for 9000ms or 9sec.

 

6.       Next go to File View and open PROFILE.cpp in the HUBO2 files->Source Files section

 

7.       When in HUBO2 files->Source Files->PROFILE.cpp find the PROF_MotionPlay29 section.  The ending is 29 because in the previous section our MotionNo was 29.  The ending number is what ever the MotionNo is equal to.  Make sure that in this section that MotionNo is equal to the same value as it is in the previous section.  In this case MotionNo = 29.

 

8.       Next scroll down to the comment “// ---------=====[ Start edit ]====-----------“ This is the start of the ONLY AREA THAT YOU EDIT TO MAKE A GESTURE.  The commented section “// ---------=====[ End edit ]====-----------“ is the end of the area that you edit to make gestures.  ONLY EDIT BETWEEN THESE TWO COMMENTED AREAS.

 

9.       To make a movement profile you need to use the FTN_half_1_cos() function.  The point of this function is to allow for movement of the joints from the joints current location to a desired location in a smooth manner.  This is done to reduce extremely fast and potentially damaging effects of step function inputs.  Please see the Definitions section above for the definitions of some of the required functions.  Also see below for more definitions.

FTN_half_1_cos(magnitude, time, start_time, duration, 0,0,&result1[0]) = Makes a smooth profile for a joint to follow instead of a step input.

-          Magnitude = max value/ending value of function.  Default 1 or -1 depending on desired direction

-          Time = time as defined in the loop.  Default time = time

-          Start_time = starting time in 10ms increments

-          Duration = how long it takes to reach the maximum value in 10ms increments

-          Do not change “0,0”

-          &result1[0] = stores the calculated profile in result1[0]

Joint Definitions “ UpperMovement[N] = “angle” where N = one of the three letter definitions below:

-          0 = Torso Yaw = XXX

-          1 = Head Yaw = XXX

-          2 = Head Pitch = XXX

-          3 = Left Shoulder Pitch = LSP

-          4 = Left Shoulder Yaw = LSY

-          5 = Left Shoulder Roll = LSR

-          6 = Left Elbow Bend = LEB

-          7 = Left Wrist Pitch = LWP

-          8 = Left Wrist Roll = LWR

-          9 = Right Shoulder Pitch = RSP

-          10 = Right Shoulder Yaw = RSY

-          11 = Right Shoulder Roll = RSR

-          12 = Right Elbow Bend = REB

-          13 = Right Wrist Roll = RWR

-          14 = Right Wrist Pitch = RWP

 

10.   We will now create a movement of the right and left arms.  Below is the timing diagram for the movement.  All noted ticks are in increments of 10ms.  The top graph shows the desired movement of the Right Shoulder Pitch (RSP) and the bottom graph shows the timing diagram of the Left Shoulder Pitch (LSP)

The X axis is time which is kept track of by the variable time and increases in 10ms increments every cycle.

The Y axis is command angle for the joint defined in degrees.

The flat section at the top of each bump is the desired target angle.  The curved section is the use of the FTN_half_1_cos() function which is used to get to that angle.  Please see the list of steps below to come up with the desired trajectory for the RSP and LSP

-          At time = 100 to time = 200 RSP moves from 0 deg to 90 deg.

o   FTN_half_1_cos( 1.0f,time,    100,100,0,0,&result1[0]);

-          At time = 300 to time = 400 LSP moves from 0 deg to 90 deg.

o   FTN_half_1_cos(1.0f,time,    300,100,0,0,&result1[1]);

-          At time = 500 to time = 600 RSP moves from 90 deg to 0 deg.

o   FTN_half_1_cos(-1.0f,time, 500,100,0,0,&result2[0]);

-          At time = 700 to time = 800 LSP moves from 90 deg to 0 deg.

o   FTN_half_1_cos(-1.0f,time,700,100,0,0,&result2[1])

-          At this point all trajectories are in percentage of the desired angle.  Because the desired final angle for each the LSP and RSP is 90 deg the function will be multiplied by the value 90 deg.

o   For the RSP the full movement is made by adding result1[0] and result2[0] together

§  res[0] = (float)(90.*(result1[0]+result2[0]));

o   For the RSP the full movement is made by adding result1[1] and result2[1] together

§  res[1] = (float)(90.*(result1[1]+result2[1]));

o   Now the trajectory data is stored in res as res[0] for the RSP and res[1] for the LSP.

-          Next the trajectories need to be applied to the trajectories in res to the proper joints.

o   For the Right Shoulder Pitch RSP

§  UpperMovement[RSP] = res[0];

o   For the Left Shoulder Pitch LSP

§  UpperMovement[LSP] = res[1];

-          BE SURE TO VERIFY THE TRAJECTORY BEFORE RUNNING IT ON HUBO