Battery Sensor
==============

.. image:: ../../../media/sensors/battery.png
  :align: center
  :width: 600


This sensor emulates the remaining charge of a battery on the robot.
It is meant to be used only as an informative measure, to be taken in
consideration by the planning algorithms. It does not prevent the robot
from working.

The charge of the battery decreases with time, using a predefined
**Discharge rate** specified as a property of the Blender object.
This rate is independent of the actions performed by the robot, and
only dependant on the time elapsed since the beginning of the simulation.

If the battery enters in a **Charging zone**, the battery will
gradually recharge.


.. cssclass:: properties morse-section

Configuration parameters for Battery Sensor
-------------------------------------------


You can set these properties in your scripts with ``<component>.properties(<property1>=..., <property2>=...)``.

- ``DischargingRate`` (float, default: ``0.05``)
	Battery discharging rate, in percent per seconds


.. cssclass:: fields morse-section

Data fields
-----------


This sensor exports these datafields at each simulation step:

- ``timestamp`` (float, initial value: ``0.0``)
	number of seconds in simulated time
- ``charge`` (float, initial value: ``100.0``)
	Initial battery level, in percent
- ``status`` (string, initial value: ``Charged``)
	Charging Status

*Interface support:*

- :tag:`socket`  as straight JSON serialization (:py:mod:`morse.middleware.socket_datastream.SocketPublisher`)
- :tag:`text`  as key = value format with timestamp and index value (:py:mod:`morse.middleware.text_datastream.Publisher`)
- :tag:`yarp`  as yarp::Bottle (:py:mod:`morse.middleware.yarp_datastream.YarpPublisher`)
- :tag:`ros`  as Float32Publisher (:py:mod:`morse.middleware.ros.battery.Float32Publisher`)


.. cssclass:: services morse-section

Services for Battery Sensor
---------------------------

- ``set_property(prop_name, prop_val)`` (blocking)
    Modify one property on a component
    
    
  - Parameters

    - ``prop_name``: the name of the property to modify (as shown the documentation)
    - ``prop_val``: the new value of the property. Note that there is no checking about the type of the value so be careful

  - Return value

    nothing 

- ``get_properties()`` (blocking)
    Returns the properties of a component.
    
    
  - Return value

    a dictionary of the current component's properties  

- ``get_local_data()`` (blocking)
    Returns the current data stored in the sensor.
    
    
  - Return value

    a dictionary of the current sensor's data 

- ``get_configurations()`` (blocking)
    Returns the configurations of a component (parsed from the properties).
    
    
  - Return value

    a dictionary of the current component's configurations  



.. cssclass:: examples morse-section

Examples
--------


The following examples show how to use this component in a *Builder* script:

.. code-block:: python


    from morse.builder import *
    
    # adds a default robot (the MORSE mascott!)
    robot = Morsy()
    
    # creates a new instance of the sensor
    battery = Battery()

    # place your component at the correct location
    battery.translate(<x>, <y>, <z>)
    battery.rotate(<rx>, <ry>, <rz>)
    
    robot.append(battery)
    
    # define one or several communication interface, like 'socket'
    battery.add_interface(<interface>)

    env = Environment('empty')
    

.. cssclass:: files morse-section

Other sources of examples
+++++++++++++++++++++++++

- `Source code <../../_modules/morse/sensors/battery.html>`_
- `Unit-test <../../_modules/base/battery_testing.html>`_




*(This page has been auto-generated from MORSE module morse.sensors.battery.)*
