.. _NAOsim:

======
NAOsim
======

What is NAOsim
----------------

NAOsim is a simulator of NAO where you can test your behaviors and algorithms in a virtual world.
You can modify the environment by inserting and modifying objects of various shapes.

.. image:: /medias/desktop/naosim/NAOsim_red_ball.png


What is NAOsim and choregraphe relation
---------------------------------------

NAOsim embeds NAOqi and therefore can be connected to Choregraphe and Monitor, 
it is a safe place to test Choregraphe's behaviors before playing them on NAO in a real environment.
In NAOsim, you can also modify the path of NAOqi in order to add your own C++ modules.

.. image:: /medias/desktop/naosim/NAOsim_and_Choregraphe.png


Which sensors and actuators are supported
-----------------------------------------

NAOsim supports the major part of NAO's sensors and actuators (
:ref:`hardware-sensors`
) :

* Motor position (Sensor & Actuator)

* Inertial board

* Force Sensitive Resistors (On/Off)

* Bumpers contact

* Camera (top and bottom)


Install NAOsim
--------------

NAOsim installer is available on Mac os X, Windows Xp and Windows 7. Linux is not supported yet.


Using NAOsim
------------

This Getting Started guide explains you how to use NAOsim and Choregraphe together to simulate
a behavior in a virtual environment.

Connecting NAOsim and Choregraphe
+++++++++++++++++++++++++++++++++

#. Launch NAOsim.

#. Create your environment:

   - Click on **New**
   - Select 'Small Apartment'
   - Open the **View > Robots** 
   - Drag & drop the model of the robot you want to simulate.

#. Click the Start button to turn on the simulation (it will launch NAOqi).

#. Launch Choregraphe.

#. Connect Choregraphe with NAOsim:

   - In Choregraphe, go to **Connection**.
   - Select your NAO (the name should include
     the name of your computer). Its icon should be: 

   .. image:: /medias/desktop/beginning_nao_bleu.png


#. You can now control the NAO with the 3dView in Choregraphe and check what NAO is seeing in the Choregraphe Video Monitor.

Handling objects in NAOsim
++++++++++++++++++++++++++

#. Add the **Objects** panel: click **View** > **Objects**.

#. Add an object in your virtual environment:

   - Select an object in the **Objects** panel.
   - In the virtual environment, click where you want the object to be added.

#. Edit an object:

   - Open the **Hierarchy View** and the **Properties** panels.
   - Select the object in the **Hierarchy View**.
   - In the toolbar, click the Move, Rotate or Scale icon.
  
     .. image:: /medias/desktop/naosim/navigation_buttons.png

   - In the virtual environment, move the cursor on the X, Y or Z axis to edit the object.

     .. image:: /medias/desktop/naosim/move_object.png

   - You can also modify the Position, the physics parameters and the Material of the object.

     .. image:: /medias/desktop/naosim/transform_properties.png

#. Delete an object:

   - Select an object either in the **Hierarchy View** panel or in the virtual environment.
   - Press the Del key.

Testing a behavior in NAOsim
++++++++++++++++++++++++++++

#. In NAOsim, create a virtual environment including objects of various shapes.

#. In Choregraphe, create a behavior and connect it to NAOsim.

#. Click the Play button in Choregraphe.

#. Check the result in NAOsim: Does it look good? Does NAO fall down?

#. Adapt your behavior and play it again.

+--------------------------------------------------+--------------------------------------------------------------+
|.. image:: /medias/desktop/naosim/NAOsim_WB2.png  | .. image:: /medias/desktop/naosim/NAOsim_track_red_ball.png  |
|   :height: 300                                   |    :height: 300                                              |
+--------------------------------------------------+--------------------------------------------------------------+

Troubleshooting
---------------

I can’t see my virtual NAO in the connection window of Choregraphe.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Make sure you clicked on the **Start** button in NAOsim to turn on your virtual robot.

Two NAO have the same name in the connection window of Choregraphe.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Select the one with the port 9559.

My NAOsim window is grey, I can't see NAO or any objects
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Example of the issue:

.. image:: /medias/desktop/naosim_bugzoom.png

You probably zoomed in or out too much (the issue can occur also if you zoomed outside NAOsim due to a bug).

#. Display the Explorer: go to **View** > **Hierarchy View**.

#. Select an item in the list.

#. Press the F key.

The window focus is now on the item selected and the issue is fixed.

Annoying warning
++++++++++++++++

When connecting Choregraphe and NAOsim, there can be the warning 'NAOqi’s version seems to differ from the Choregraphe you are using'.

#. In NAOsim, go to **File** > **Preferences** and click **Browse** to select another :ref:`naoqi-sdk path <cpp-introduction>`.
   Check the presence of the files bin/naoqi-bin and bin/nao_simulation_hal. Uncomment the ``dcm_hal`` line in naoqi-sdk/etc/naoqi/autoload.ini.

#. Restart the simulation : in NAOsim click **Stop** and **Start**.

#. Reset the connection in Choregraphe.