SIGVerse with Python

The aim of this tutorial is to

  • write a python module using pygame that captures mouse movements
  • to present setting of environmental variables for writing Sigservices in Python
  • import the module inside Sigservice and send data to Sigserver
  • making a .sig file and loading it into Sigviewer

To use this tutorial, the use needs to have boost.python libraries installed and configured on his visual studio project. I have shown how to do that in previous tutorial.

  • Writing python module for capturing mouse movements using pygame
  • Please install pygame from here. The version I am using is pygame-1.9.1.win32-py2.7.msi. If you use 32 bit python, please use 32 bit version of pygame. It should be set in your python path.
  • Please copy the following code and name it as "mouseModule.py"

When you run this code, it captures 100 mouse movements and captures the relative distance between successive mouse movements. To change the iteration from 100 to some other number, please modify the counter. We shall now be importing this user defined module in our code.

  • Create a Visual Studio project
  • I have used Visual Studio 2008.
  • Please use Ctl+Shft+N to create a New Project. Lets call it "My Service Test".
  • Setting environmental variables.

You need to have SigService library on your disk. Please download it from here I am using SIGService_v2-1-0 and its location on my disk is at F:\Sigverse\SIGService_v2-1-0\SIGService_v2-1-0

  • 1. Go to: Configuration Properties-->C/C++-->General-->Additional Include Directories Add:
        "F:\Sigverse\SIGService_v2-1-0\SIGService_v2-1-0\include";
         C:\Python27\include;
        "C:\Boost\include\boost-1_54"
  • 2. Go to Configuration Properties-->Linker-->General-->Additional Library Directories

"F:\Sigverse\SIGService_v2-1-0\SIGService_v2-1-0\lib\Debug"; C:\Python27\libs; C:\Boost\lib\i386

  • 3. Go to Configuration Properties-->Linker-->General-->Output File.
     $(OutDir)\$(ProjectName).sig
  • 4. Go to Configuration Properties-->Linker-->Input-->Additional Dependencies
           SIGService.lib 
           C:\Python27\libs\python27.lib 
           C:\Boost\lib\i386\boost_python-vc90-mt-gd-1_54.lib
  • Writing a source code C++ file, name it as "MyService.cpp". Please place the python module "mouseModule.py" in the same directory as C++ code.

The above code, imports the python module which captures relative positions of mouse movements. Those positions are then sent to Sigserver for moving objects inside Sigviewer.

  • Debug the code and place the following files into project_name/Debug directory ( In my case it is F:\Sigverse\MyServiceTest\Debug)
    • mouseModule.py
    • boost_python-vc90-mt-gd-1_54.dll
  • Please build the code, using F7. You can see that MyServiceTest.sig is created in the project_name/Debug directory.
  • Now, lets go to the server side and see how our service works.

1. Create a project directory using

         sigcreate.sh  NewProject

2. Copy the following code and name it as LToolController.cpp

  • Run the code to make .so file.
           ./sigmake.sh    LToolController.cpp

3. Create the world file, which has a stick tool and object. Name it as "ToolsOnTable.xml"

  • The robot_test.xml to create xml file for stick tool.
  • The robot_text.x3d to create stick tool.
  • The robot_box.xml to create the xml file of small box.
  • The robot_box.x3d to create a small box.

4. Please load the world file

    sigserver.sh -w ./ToolsOnTable.xml -p write_your_port_number

5. Go to Services-->Add-->MyServiceTest.sig and then Services-->Start

This shall add your mouse service.

6. Please click "Start" to run the simulation.

7. When you use left click the mouse events are captured and their relative positions are recorded. Based on these relative positions, the tool moves which hits the target object. On making right click, the event capturing is stopped.

Counter: 2497, today: 1, yesterday: 2

Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2014-05-09 (Fri) 16:26:30 (3645d)