Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can battery #793

Merged
merged 26 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Common settings
BasedOnStyle: Google
TabWidth: 4
IndentWidth: 4
UseTab: Never
ColumnLimit: 200

Language: Cpp

SortIncludes: false
DisableFormat: false
Standard: Cpp11
SortIncludes: false
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false

4 changes: 2 additions & 2 deletions conf/iCubFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ checkandset_dependency(Qt5)

if(icub_firmware_shared_FOUND AND ICUB_USE_icub_firmware_shared)
# icub-firmware-shared 4.0.7 was actually a wrong version exported by icub-firmware-shared <= 1.15
if(icub_firmware_shared_VERSION VERSION_GREATER 4 OR icub_firmware_shared_VERSION VERSION_LESS 1.25.1)
message(FATAL_ERROR "An old version of icub-firmware-shared has been detected, but at least 1.25.1 is required")
if(icub_firmware_shared_VERSION VERSION_GREATER 4 OR icub_firmware_shared_VERSION VERSION_LESS 1.26.0)
message(FATAL_ERROR "An old version of icub-firmware-shared has been detected, but at least 1.26.0 is required")
endif()
endif()

Expand Down
1 change: 1 addition & 0 deletions src/libraries/icubmod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ yarp_begin_plugin_library(icubmod QUIET)
add_subdirectory(imuFilter)
add_subdirectory(embObjPSC)
add_subdirectory(embObjPOS)
add_subdirectory(embObjBattery)
if (ICUB_ICUBINTERFACE_EXPERIMENTAL)
add_subdirectory(imu3DM_GX3)
endif()
Expand Down
40 changes: 40 additions & 0 deletions src/libraries/icubmod/embObjBattery/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (C) 2022 Istituto Italiano di Tecnologia (IIT)
# All rights reserved.
# Author: Luca Tricerri
# This software may be modified and distributed under the terms of the
# BSD-3-Clause license. See the accompanying LICENSE file for details.

yarp_prepare_plugin(embObjBattery CATEGORY device
TYPE yarp::dev::embObjBattery
INCLUDE embObjBattery.h
EXTRA_CONFIG WRAPPER=analogServer)

IF (NOT SKIP_embObjCanBatterysensor)


set(ICUB_COMPILE_EMBOBJ_LIBRARY ON CACHE INTERNAL "use the embObjLib lib")


INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

yarp_add_plugin(embObjBattery embObjBattery.cpp embObjBattery.h)
TARGET_LINK_LIBRARIES(embObjBattery ethResources)
icub_export_plugin(embObjBattery)

yarp_install(TARGETS embObjBattery
COMPONENT Runtime
LIBRARY DESTINATION ${ICUB_DYNAMIC_PLUGINS_INSTALL_DIR}
ARCHIVE DESTINATION ${ICUB_STATIC_PLUGINS_INSTALL_DIR}
YARP_INI DESTINATION ${ICUB_PLUGIN_MANIFESTS_INSTALL_DIR})

if (BUILD_TESTING)
add_library(embObjBatteryUT STATIC embObjBattery.cpp embObjBattery.h)
target_link_libraries(embObjBatteryUT ethResources
YARP::YARP_dev
icub_firmware_shared::embobj)

target_include_directories(embObjBatteryUT PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
endif()

ENDIF (NOT SKIP_embObjCanBatterysensor)

191 changes: 191 additions & 0 deletions src/libraries/icubmod/embObjBattery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# 1. General info
The device's purpose is to make it possible to connect up to the `CanBattery` sensor to a single EMS board.
This device works with the `bms` board. Note that the board can not be programmed for different message rates.

## 1.1. Prerequisite
The following modules should be included in the compilation process:

```cmake
ENABLE_icubmod_embObjCanBattery ON
```

# 2. XML configuration file

This device should be used with XMLs like the following:

The root XML:
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE robot PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd">

<robot name="testFT" build="1" portprefix="icub" xmlns:xi="http://www.w3.org/2001/XInclude">
<params>
<xi:include href="hardware/electronics/pc104.xml" />
</params>

<devices>


<!-- ANALOG SENSOR CANBATTERY -->
<xi:include href="wrappers/CanBattery/testCanBattery_wrapper.xml" />
<xi:include href="hardware/CanBattery/eb1-j0-strain2-canbattery.xml" />


</devices>
</robot>
```

The device XML in `hardware\CanBattery` (refer to the root XML file):
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE device PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd">

<device xmlns:xi="http://www.w3.org/2001/XInclude" name="eb1-j0-strain2-canbattery" type="embObjBattery">

<xi:include href="../../general.xml" />

<xi:include href="../../hardware/electronics/eb1-j0-eln.xml" />

<group name="SERVICE">

<param name="type"> eomn_serv_AS_battery </param>

<group name="PROPERTIES">

<group name="CANBOARDS">
<param name="type"> bms </param>

<group name="PROTOCOL">
<param name="major"> 0 </param>
<param name="minor"> 0 </param>
</group>
<group name="FIRMWARE">
<param name="major"> 0 </param>
<param name="minor"> 0 </param>
<param name="build"> 0 </param>
</group>
</group>

<group name="SENSORS">
<param name="id"> battery1 </param>
<param name="board"> bms </param>
<param name="location"> CAN2:13 </param>
</group>

</group>


<group name="SETTINGS">
<param name="enabledSensors"> battery1 </param>
<param name="acquisitionRate"> 1000 </param> <!-- msec -->
</group>


</group>

</device>
```

And the XML wrapper in `.\wrappers\CanBattery` (refer to the root XML file)::

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE devices PUBLIC "-//YARP//DTD yarprobotinterface 3.0//EN" "http://www.yarp.it/DTD/yarprobotinterfaceV3.0.dtd">


<device xmlns:xi="http://www.w3.org/2001/XInclude" name="battery_wrapper" type="batteryWrapper">
<param name="period"> 1 </param>
<param name="name"> /icub/battery </param>

<action phase="startup" level="5" type="attach">
<paramlist name="networks">
<!-- The param value must match the device name in the corresponding body_part-ebX-jA_B-strain.xml file -->
<elem name="battery"> eb1-j0-strain2-canbattery </elem>
</paramlist>
</action>

<action phase="shutdown" level="5" type="detach" />
</device>
```

Important note:
`<elem name="battery"> eb1-j0-strain2-canbattery </elem>`
should contains the device name `eb1-j0-strain2-canbattery` of the device file.


# 3. Yarp output

## 3.1. Ports

As for the wrapper file:

```bash
/<robot_name>/battery/data:o
/<robot_name>/battery/rpc:o

```

## 3.2. Output format

The output from bash commend
```bash
yarp read ... /icub/battery/data:o
```

`40 3.300000011920928955078 80.0 31.0 0`
`voltage -- current -- charge -- temperature -- status`

Voltage in Volt
Current in Amper
Charge in percent
Temperature in degree Celtius
Status not used for now

# 4. Battery client
To receive data from the device you should use the iBattery interface.
See a complete example here:
https://github.com/robotology/yarp/tree/master/src/yarpbatterygui

# 5. Debug

## 5.1. Install folder
If you have already installed robotology-superbuild and you have cloned icub-main (and you are working here) overwrite robotology-superbuild binary like this in your icub-main:
```bash
CMAKE_INSTALL_PREFIX <path_to_robotology>/robotology-superbuild/build/install
```

## 5.2. Visual studio code debugging
Use the following launch.json
```JSON
{
"name": "App debug battery sensor",
"type": "cppdbg",
"request": "launch",
"program": "<robotology-path>/robotology-superbuild/build/install/bin/yarprobotinterface",
"args": [],
"stopAtEntry": false,
"cwd": "<xmlconfig-files>/yarprobotinterface-config-canbattery",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"miDebuggerPath": "/usr/bin/gdb",
}
```

# 6. Unittest
The device has a set of unittest that can be activated with:
```
BUILD_TESTING ON
```
Loading