As seen in “Part 1: The Basics” the Hubo has a loop called TimerHandler() which allows the system to run in Hard Real-Time, i.e. with a fixed sampling rate. This tutorial will show you the basics of making the original Hubo, KHR2, make arm gestures using this loop and other pre-made functions and methods. The ultimate goal of this tutorial is to make Hubo’s head move up and down smoothly.
The code below in Figure 2 shows the function that executes when you press the button Man1 (B), Figure 1.
Figure 1: Button to execute function in CGesturePage3::OnPage3Man1B()
The code in Figure 2 below defines the desired angle for each joint. In the code below each joint is given the desired angle of 0o except for the head pitch. The head pitch is given a desired angle as the result of the funciton 15cos(2πt/100). Note that t is an integer where each integer value is 10ms. The reason why the cos() function was chosen instead of the sin() function was because the initial value of cos() is the same as the home value of the head, 0o. In the main for loop “for(t=0, t<T,t++)” the local integer t is incremented and desired value for that time is stored in the public variable in SharedMemory called UpBody_MTN_CAP_Data[t][n] where n is the joint number.
The highlighted portion in Figure 2 is the portion of the code that sends the current value of 15cos(2πt/100) to the head pitch.
Figure 2: Code to execute when Man1 (B) button is pressed. Moves head up and down by ±15o, centered at 0o, and at a frequency of 1Hz.
Please note that the code will only execute for up to T increments of t, i.e. T/100 sec.
After the desired angle for each joint is put into UpBody_MTN_CAP_Data[t][n] the function talked about in “Part 1: The Basics” called TimerHandler(). Within this code the proper message is sent to the CAN Bus to set each joint to the desired angle denoted by UpBody_MTN_CAP_Data[t][n]. Please note that the code inside of TimerHandler() is extremely long and messy for the KHR2 but this is NOT the same code that will be used on the New Hubo.
The final result for running this code can be found in the video below.