How To Program Hubo

How To Program Hubo

Part 1: The Basics



Hubo’s primary computer runs Windows XP Embedded with Real-Time Extensions (RTX) for windows.  All Hubo’s code is compiled into a Win32 Executable using Microsoft’s Visual C++ 6.0.  This executable is then run within the Windows XP Embedded environment.  Please note that the RTX makes sure that the program gets the resources that it needs from Windows and also ensures that it will run in Hard Real-Time with a sampling period of T=0.01sec.  If Windows crashes while the Hubo code is running, RTX ensures that the Hubo will still function properly because it is not dependent on windows to run.

Each joint is controlled by an independent motor.  Each motor is controlled by a motor controller which takes command from a CAN bus.  Each motor driver has the ability to return the position of the motor as well as analog data from an attached device such as an accelerometer or gyro.



In order to connect to Hubo you will need two (2) things. 

1.       A Hubo with a network connection and a known IP address

2.       A computer with a Remote Desktop Protocol (RDP) such as Window’s Remote desktop or Linux’s rDesktop.  Note this computer must be connected to the same network as Hubo


For this example Hubo will have an IP of and the Window’s Remote Desktop will be used.


In Windows XP open Remote Desktop Connection by going to the Start MenuàAll ProgramsàAccessoriesàRemote Desktop Connection

Type in the IP address in the given field and press connect


Figure 1: Remote Desktop Connection Initial Menu.  Type in the IP address and press Connect



Be sure to know the login information for the given Hubo.  In this case the username is Hubo and the password is 1234


Figure 2: Login Screen for Microsoft’s Remote Desktop


After the connection is made and you are logged in you can treat Hubo like any Windows XP computer.


The next step is to open Microsoft’s Visual Studio C++ 6.0 by going to the Start MenuàAll ProgramsàMicrosoft Visual Studio 6.0àMicrosoft Visual C++ 6.0.  Then open the workspace for the Hubo project that you will be working with, this is done by going to FileàOpen Workspace.  Be sure to open the workspace file HUBO2.dsw.


Figure 3: Microsoft’s Visual C++ 6.0 with HUBO2.dsw open


The Hubo code is broken up in to two separate parts, the “HUBO2 files” and the “HUBO2Win files”.  The “HUBO2 files” is the system running with RTX.  This system manages the CAN connection, motor commands, and sensor data retrieval.


HUBO2 files:

The “HUBO2 files” contain three important source files and one extremely important header file:

1.       CAN.cpp – Takes care of the CAN communication protocol

2.       Core.cpp – Contains the primary loop that all of the calculations will be done to control the Hubo

3.       RTX.cpp – Real-Time Extensions source, ensures that the system runs in Hard Real-Time

4.       SharedMemory.h – This is the most important header file.  Both “HUBO2 files” and “HUBO2Win files” have read and write access to this header file.  This is how “HUBO2 files” communicates with the GUI in “HUBO2Win files.”


HUBO2Win files:

The “HUBO2Win files” can be treated as a generic Window’s Visual Studios C++ project.  You can create GUIs and graphs from the data in SharedMemory.h as well as send commands via writing to SharedMemmory.h


Important Functions Within Core.cpp


InitParameters() sets the initial values for all of the parameters and flags for the system.  This must be run before the primary code is started.  Note that as the system gets more complex more parameters can be added to the function.


void InitParameters(void)


                unsigned char i;

                pSharedMemory->bExitFlag =                   FALSE;                                   // Tells the program to stay open until closed

                pSharedMemory->Read_FTS_Flag =       FALSE;                                   // Force Torque Sensor Not Read Yet


                for(i=0 ; i<8 ; i++)


                                TxData[i] = 0;





 Figure 4: InitParameters() located in Core.cpp within “HUBO2 files”



main() ensures that all of the data has been sent through the CAN Buss


void main(void)





                while((pSharedMemory->bExitFlag)==FALSE)    // this is the main loop  it will run as long as dExitFlag is not true

                {                                                                                              // this will run until the dialog box is closed


                                if(pSharedMemory->Tx_Flag == TRUE)


                                                CanSendMsg(0, pSharedMemory->Tx_ID, pSharedMemory->Tx_Data, pSharedMemory->Tx_DLC, 0);  //default

                                                                                                                                                                                                                                                                                                                                                                                                                // this loop runs independently of TimerHandler                              


                                                pSharedMemory->Tx_Flag = FALSE;  // states that everything has been transmitted







 Figure 5: main() located in Core.cpp within “HUBO2 files”



TimerHandler() is where all calculations and commands for the Hubo will go.  This process is ensured to be running in Hard Real-Time


void RTFCNDCL TimerHandler(PVOID context)


// Place code here



Figure 6: TimerHandler() located in Core.cpp within “HUBO2 files”