---
description: In this tutorial you will learn how to integrate the BMS772 into the B3RB.
---

# BMS772 integration

> 1. [Introduction](#introduction)
> 2. [Hardware setup](#hardware-setup)
>    1. [prepare the 3D printed mount](#prepare-the-3d-printed-mount)
>    2. [solder connectors and make cables](#solder-connectors-and-make-cables)
>    3. [balancing leads connection](#balancing-leads-connection)
>    4. [Setup validation - emulating a battery](#setup-validation-emulating-a-battery)
> 3. [Software setup in the BMS](#software-setup-in-the-bms)
> 4. [Software setup in NavQP](#software-setup-in-navqp)
> 5. [References](#references)

{% hint style="danger" %}
It is important to take precautions when working with batteries:

* Before connecting a  battery to the BMS, test it first using a power supply which has current limiting enabled. See section: Setup validation. This is to avoid damage that could occur because of bad soldering, a short of some kind  or swapped wires.
* LiPo batteries can be dangerous and catch on fire. When first plugging in a LiPo battery, please do it outdoors in an area that is fire-safe. Have a fire extinguisher nearby.
{% endhint %}

## Introduction

The RDDRONE-BMS772 is a standalone BMS reference design supporting 3 to 6 cell batteries.

The General Purpose MCU S32K144  provides great flexibility and communication to a PX4 based FMU via UAVCAN or I2C/SMBus. More information about the board can be found in references \[1]\[2].

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FG4fFT29LYspEQSJIGmpR%2FRDDRONE-BMS772-ISO.webp?alt=media&#x26;token=1f8d3c25-565d-44f7-a487-a08d9b9a0ad5" alt=""><figcaption></figcaption></figure>

The BMS will be integrated in the system following the wiring diagram below:

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FQqzzqafuXg5wGij6SdAO%2FPicture79.png?alt=media&#x26;token=76448363-823c-4479-a223-ff6a442584d3" alt=""><figcaption><p>Wiring diagram</p></figcaption></figure>

## Hardware setup

For setting up the hardware, we need:

* prepare the 3D printed mount
* solder connectors and make cables
* solder the balance leads and make its extension cable
* prepare a battery emulator setup

### Prepare the 3D printed mount for the RDDRONE-BMS772 board

This particular 3D print will allow the RDDRONE-BMS772 to connect to the pre-production version of MR-B3RB lower chassis metal frame. Future versions may not need this adapter, or may be able to just use standoff's directly.

{% file src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FeNDy6Kfqw3d9FOkuCXDc%2FBMS772%20Mount%20for%20B3RB.stl?alt=media&token=db6e4e7c-b75f-4eab-887f-eb7f9cdae366" %}

### Solder connectors and make cables

We recommend pluggable cable connectors as shown below. Follow these images for guidance.\
Some XT60 connectors have a "back shell" to also help cover the solder joints. The backshell is preferable.

<div><figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FcXa3L8XQW3ru0x6UfJ2R%2Fbms_1.jfif.png?alt=media&#x26;token=74bbf462-e976-4ef9-abfa-dc77251e2605" alt=""><figcaption><p>Option 1 : solder XT90 connectors and make adapter cables</p></figcaption></figure> <figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FdqUs4djDWUy21p1nhwPP%2Fbms_2.jfif.png?alt=media&#x26;token=9a5881bf-5f1d-4956-b8b0-c70f0aec9a44" alt=""><figcaption><p>Minimum 20 cm</p></figcaption></figure></div>

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FYvcdIvbs5yVgZKDgXReZ%2Fbms_3.jfif.png?alt=media&#x26;token=e411470c-de66-453b-86e3-59313360d1ce" alt=""><figcaption><p>Option 2 : use XT60 connectors</p></figcaption></figure>

### Balance leads connection

Because of the limited space on the B3RB. it is preferable to use a balancing leads connector that points upward.  This will better clear the PDB that is adjacent to this board, and allow you to more easily plug in the battery's balancing cable later. Solder the white balance connector as shown below:

{% hint style="info" %}
If you cannot obtain a vertical balance lead connector,  while sub-optimal, the right angle connector that ships with the board may be modified to stand upright by removing the tabs at the rear. Be extra careful about the correct orientation and alignment&#x20;
{% endhint %}

<div><figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FHScEdeKSY5gjH5CE8T4Y%2FPicture75.jpg?alt=media&#x26;token=85017c9f-1f37-4f7a-aff3-287b763f1e04" alt=""><figcaption><p>Correct vertical orientation connector</p></figcaption></figure> <figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2F8leusT5JCq1nrvaj7fSz%2FPicture76.jpg?alt=media&#x26;token=47980232-c43f-4f55-a385-b972620a9eb7" alt=""><figcaption><p>Incorrect - horizontal connector </p></figcaption></figure></div>

### Balance leads extension cable

You will also need to make an extension cable for the balance leads connector. The leads that typically come as part of the battery is quite short. The suggested cable length is approximately 17cm.

{% hint style="info" %}
The extension cable can act as a fuse. While the wires in the picture below are thin, they can blow up in case of short circuit, the a battery damage could be avoided.
{% endhint %}

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FH7zVMXp7DOK6aAD9WoKA%2FSelected%20photo%20(4).jfif?alt=media&#x26;token=98f35aad-7532-46b1-a472-4d774bc94222" alt="" width="375"><figcaption></figcaption></figure>

### Setup validation - emulating a battery

In this section we will prepare a setup to emulate the battery using a power supply. For this setup we need:

* 4 x 1kΩ resistors
* 2 wires: one black and one red
* Female balance leads connector with wires

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FnbFsDYpujCvPrcEUNbhs%2FSelected%20photo.jfif?alt=media&#x26;token=202e2b95-bbac-4130-bfec-8cdb736da057" alt="" width="375"><figcaption><p>Battery cells emulator</p></figcaption></figure>

Here are the steps:

1. Connect the female balance leads connector with wires and cut them to make them short.
2. Solder the resistors in series then solder two cables in both sides (black and red) as depicted in the picture above. Please make sure that the sides of the black and red wires are similar to the picture.
3. connect Black and red wires of the battery cells emulator to - and + input from the power supply.
4. Set the voltage in your power supply to 12V, then plug the input port to the power supply and the output port to the load that you are powering.

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FVlPDjfNo9gsrhxXcUdkl%2Fshared%20image%20(3).jfif?alt=media&#x26;token=e592458e-6c9a-4f2a-8779-e505166102f4" alt=""><figcaption></figcaption></figure>

## Software setup in the BMS

You can compile a binary from this GitHub repository: [https://github.com/NXPHoverGames/RDDRONE-BMS772](https://github.com/NXPHoverGames/RDDRONE-BMS772/blob/main/Binary/nuttx.bin) or flash the existing binary [https://github.com/NXPHoverGames/RDDRONE-BMS772/blob/main/Binary/nuttx.bin](https://github.com/NXPHoverGames/RDDRONE-BMS772/blob/main/Binary/nuttx.bin) (follow [these instructions](https://github.com/NXPHoverGames/RDDRONE-BMS772?tab=readme-ov-file#using-the-command-line-interface-cli-of-the-bms)).

Activate the cyphal can and setup the can id:

```
nsh> bms set can-mode cyphal
nsh> bms set cyphal-node-static-id 100
nsh> bms save
nsh> reboot
```

## Software setup in NavQP

In this section, we present three methods to display received messages via CAN:

* using yakut CLI
* using pycyphal library
* using pycyphal library and ROS2&#x20;

#### Prepare environment variables and DSDL namespace

Before the three next steps, you need to prepare the environment variables and add the DSDL namespace as follow:

```
mkdir -p ~/.cyphal
wget https://github.com/OpenCyphal/public_regulated_data_types/archive/refs/heads/master.zip -O dsdl.zip
unzip dsdl.zip -d ~/.cyphal
mv -f ~/.cyphal/public_regulated_data_types*/* ~/.cyphal
```

```
export UAVCAN__NODE__ID=42 
export UAVCAN__CAN__IFACE=socketcan:can0
export UAVCAN__CAN__MTU=8
export CYPHAL_PATH=/home/user/.cyphal
```

#### Using Yakut CLI

Yakút is a simple cross-platform command-line interface (CLI) tool for diagnostics and debugging of Cyphal networks. (For more information refer to \[3])

The BMS772 software is already publishing three messages:

* **type**: reg.udral.physics.electricity.SourceTs\_0\_1, **port**: 4096&#x20;
* **type**: reg.udral.service.battery.Status\_0\_2, **port**: 4097
* **type**: reg.udral.service.battery.Parameters\_0\_3, **port**: 4098

Print published Cyphal message in a terminal:

<pre><code><strong># yakut sub --with-metadata port:type
</strong><strong># Run the following commands in separate terminals
</strong><strong>
</strong>yakut sub --with-metadata 4096:reg.udral.physics.electricity.sourcets
yakut sub --with-metadata 4097:reg.udral.service.battery.status
yakut sub --with-metadata 4098:reg.udral.service.battery.parameters 
</code></pre>

#### Using pycyphal library

First, clone the following repository:

```
git clone git@github.com:mounalbaccouch-nxp/BMS_cyphalcan.git
```

Run the script to print the received cyphal messages:

```
cd BMS_cyphalcan
python3.10 cyphal_bms_print_status.py
```

#### Using pycyphal library and ROS2

Clone the following repository:

```
git clone git@github.com:mounalbaccouch-nxp/BMS_cyphalcan.git
```

Run the ros2 node:

```
cd BMS_cyphalcan
python3.10 cyphal_bms_ros2-pub_status.py
```

Print the topic:

```
ros2 topic echo /battery_state
```

Once the topic is publishing battery state messages, we can display it in Foxglove. Fist add the topic to the while listed topics in robot.launch.py file

In your PC, download the following layout file and add it to Foxglove studio:

{% file src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FFicV68EJOWddtaF4KTgy%2Fb3rb%20bms.json?alt=media&token=fa5bbe62-9270-477e-9d53-4c1f7da82b8b" %}

You should see two different tabs: one tab _**General**_ for displaying the B3RB topics and one tab _**Battery**_ for displaying the battery status raw data:

<figure><img src="https://396338415-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU93yDWZcgjXGgsC1Duqv%2Fuploads%2FyGLR2sJLMhWHUKBJR5Vi%2FScreenshot%20from%202024-04-02%2017-29-58.png?alt=media&#x26;token=0e26c099-3380-4eac-aa3e-77585deb213c" alt=""><figcaption></figcaption></figure>

## References

\[1] BMS gitbook: [https://nxp.gitbook.io/rddrone-bms772/software-guide-px4/introduction](https://nxp.gitbook.io/rddrone-bms772/software-guide-px4/introduction)

\[2] [https://www.nxp.com/design/design-center/designs/smart-battery-management-for-mobile-robotics:RDDRONE-BMS772](https://www.nxp.com/design/design-center/designs/smart-battery-management-for-mobile-robotics:RDDRONE-BMS772)

\[3] [https://github.com/OpenCyphal/yakut](https://github.com/OpenCyphal/yakut)















































































































































































































































































































































































































































































































































































































































































































































































































































































































































##
