**2.5 Control system**

204 Haptics Rendering and Applications

The design of the hardware system is characterized by its compactness and low cost. The HD is composed by a Single Board Computer (SBC) with Windows XP, a LCD screen and a

Haptic Interface actuated by two DC motors (Figure 8).

Fig. 8. Hardware unit has been designed to fit into a small acrylic box.

Fig. 9. The DC Motors and Optical Encoders are mounted on the rear of the desk.

Fig. 7. Kinematics of the system

The base control system of the HD has been designed and implemented with MatlabTM Version 6.5 and Simulink Version 5.0. Due to the restrictions of Windows operating system to execute "hard" real-time applications; the Matlab´s Real-time Workshop provides two solutions to implement the real-time controller without adding additional hardware to the system: Real-Time Windows Target (RTWIN) and Generic Real-Time Target (GRT).

The Real-Time Windows Target uses a small real-time kernel to ensure the real-time application runs in real time. The real-time kernel runs at CPU ring zero (privileged or kernel mode) and uses the built-in PC clock as its primary source of time. In order to share the data from the Real-Time Windows Target kernel to the outside world (i.e. graphical system), an Sfunction was written as a SimViewing device which lets the creation of a shared memory by means of a static library. Such S-function does not compile into real-time code but acts as a Simulink External mode interface instead. This is due under the real-time kernel, the Win32 API cannot be executed as a component of the real-time application. One drawback of this implementation is that the updating time of the data send to the external application is too low, although the real-time control loop can achieve frequencies up to 2k Hz.

Fig. 10. Architecture of the system.

Training Motor Skills Using Haptic Interfaces 207

In the case of the GRT, the I/O ports cannot be accessed directly, due to the restrictions of the OS. This problem can be solved by using the PortTalk utility which allows the permissions to the real-time code to access the I/O ports. Therefore, at this moment, we have implemented the base control by compiling the system model under the generic real-

This control system was implemented on the same architecture of the target application system. This device was made by an embedded PC (PIV 1.4GHz 1 GB RAM). Specific I/O board for detecting the encoder position and for generating the DAC command to be forwarded to drivers where implemented on the ISA and PC104 busses offered by the embedded board. The desktop backside was designed in order to host motors, power supply, hard disk, power drivers, mother boards and IO boards, all within a minimal regular square box as shown in Figure 9. The high integration achieved has allowed us to implement all control procedures and drivers within the hosting OS kernel (Windows XP). Several functional control solutions are available to use the system: a basic mouse replacement toolkit allow to make use of the system interface to control the pointer position within the screen and interact to the GUI; it is also possible to directly control the hardware device by software and or control CAD; a set of functionalities libraries also implement

In order to access the resources of the operating system, the mouse functionalities have been replaced by computing the end-effector position and by reading the signals coming from the buttons attached to the HD. Just after the real-time control is started, the system cursor is controlled, by using the mouse Win32 APIs, so that the contact point position is used to

As it was explained before, the contact position is computed by the real-time application and then, it is transferred to the shared memory. Then, the non-real time application developed with Visual C++, obtains the position and transform it to screen coordinates.

time target, with a sampling frequency of 1k Hz.

main feature to facilitating integration within application.

Fig. 13. The drawing interface window is shown.

**2.6 Graphical system** 

refresh cursor's position.

On the other hand, the Real-Time Workshop provides a generic real-time development target. The generic real-time (GRT) target provides an environment for simulating fixed-step models in single or multitasking mode. A program generated with the GRT target runs the control model as a stand-alone program under the computer. The real-time execution is achieved by controlling the real-time clock using the multimedia timers (such capability can be done by modifying the grt\_main.c file). Such timers have the highest resolution under the Windows OS, with a minimum resolution of 1 millisecond. The data is shared with the graphical application also by a static library (Figure 11).

Fig. 11. Shared memory is managed by means of a static library

A calibration phase of the HI has been implemented to measure correctly the joint positions so that we can assure the coincidence between the haptic and graphical information. This phase consists on moving both links, using a velocity control, into a well know configuration (Figure 12), where the difference between the real joint position (q1= 130o and q2= 170 o) and the measured joint position is computed and used to correct the signal coming from the encoders.

Fig. 12. The reset position for calibrating the HI is shown.

On the other hand, the Real-Time Workshop provides a generic real-time development target. The generic real-time (GRT) target provides an environment for simulating fixed-step models in single or multitasking mode. A program generated with the GRT target runs the control model as a stand-alone program under the computer. The real-time execution is achieved by controlling the real-time clock using the multimedia timers (such capability can be done by modifying the grt\_main.c file). Such timers have the highest resolution under the Windows OS, with a minimum resolution of 1 millisecond. The data is shared with the

A calibration phase of the HI has been implemented to measure correctly the joint positions so that we can assure the coincidence between the haptic and graphical information. This phase consists on moving both links, using a velocity control, into a well know configuration (Figure 12), where the difference between the real joint position (q1= 130o and q2= 170 o) and the measured joint position is computed and used to correct the signal coming

graphical application also by a static library (Figure 11).

Fig. 11. Shared memory is managed by means of a static library

Fig. 12. The reset position for calibrating the HI is shown.

from the encoders.

In the case of the GRT, the I/O ports cannot be accessed directly, due to the restrictions of the OS. This problem can be solved by using the PortTalk utility which allows the permissions to the real-time code to access the I/O ports. Therefore, at this moment, we have implemented the base control by compiling the system model under the generic realtime target, with a sampling frequency of 1k Hz.

This control system was implemented on the same architecture of the target application system. This device was made by an embedded PC (PIV 1.4GHz 1 GB RAM). Specific I/O board for detecting the encoder position and for generating the DAC command to be forwarded to drivers where implemented on the ISA and PC104 busses offered by the embedded board. The desktop backside was designed in order to host motors, power supply, hard disk, power drivers, mother boards and IO boards, all within a minimal regular square box as shown in Figure 9. The high integration achieved has allowed us to implement all control procedures and drivers within the hosting OS kernel (Windows XP).

Several functional control solutions are available to use the system: a basic mouse replacement toolkit allow to make use of the system interface to control the pointer position within the screen and interact to the GUI; it is also possible to directly control the hardware device by software and or control CAD; a set of functionalities libraries also implement main feature to facilitating integration within application.
