# DEMO: UAVCAN node servo pwm control

The idea is to control a servo motor or ESC via the CAN board using the UAVCAN protocol. This is useful to decentralize the processing from the FMU to multiple CAN boards in case of having multiple PWM units.&#x20;

Next, we will show how to connect a CAN board to the Ubuntu 22.04 PC and send PWM commands.

### Hardware setup

* (1) UCANS32K1SIC board&#x20;
* (3) USB-TTL-3V3: the GND black wire should be mounted at the top when the serial debug connector is on the left. &#x20;
* (2) Adapter board&#x20;
* (4) CAN to USB adapter board&#x20;
* (5) debug cable: to be able to communicate with the board via nutshell cmdline.&#x20;
* (6) CAN cable: mount the CAN cable at the top right connector.&#x20;
* (7) A resistor board: mount this board below the CAN cable connector&#x20;
* (8) Power supply: make sure to not exceed 5 Volts&#x20;
* (9) Servo motor for testing&#x20;

<figure><img src="https://2042189127-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M7FJ_hQKd8L0MNgduui%2Fuploads%2FKUVVGBabqHGNZJKhXnEo%2FPicture10.jpg?alt=media&#x26;token=d5c60374-c6e0-4b0a-b230-1492b90e37eb" alt=""><figcaption></figcaption></figure>

### Software setup

Install drone\_can\_gui tool:

```
sudo apt-get install -y python3-pip python3-setuptools python3-wheel 
sudo apt-get install -y python3-numpy python3-pyqt5 python3-pyqt5.qtsvg git-core 
sudo pip3 install git+https://github.com/DroneCAN/gui_tool@master 
```

### Usage

* Set up can interface&#x20;

Open a terminal and type these two lines &#x20;

```
sudo ip link set can0 type can bitrate 1000000 
sudo ip link set up can0
```

* Verify can interface&#x20;

Check whether can0 interface figures in network interfaces list:&#x20;

```
ifconfig  
```

Double check by dumping CAN bus traffic&#x20;

```
candump can0 
```

* Verify pwm status&#x20;

In a nutshell, check the status of PWM in your board&#x20;

```
pwm_out status 
```

* Start drone gui tool&#x20;

```
dronecan_gui_tool 
```

<figure><img src="https://2042189127-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M7FJ_hQKd8L0MNgduui%2Fuploads%2FwH4ZcyraAZrZ82FoHvlm%2FPicture11.png?alt=media&#x26;token=6e716656-60f1-4be7-92d9-68c203d03ec9" alt=""><figcaption><p>dronecan_gui_tool startup</p></figcaption></figure>

Press ok&#x20;

You should see your ucans32 device in the list of nodes:

<figure><img src="https://2042189127-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M7FJ_hQKd8L0MNgduui%2Fuploads%2FXaIuc6qhCnyNAdAzYHHf%2FPicture12.png?alt=media&#x26;token=b8ee65c8-b22e-4482-a608-16f1e259ba3a" alt=""><figcaption><p>dronecan_gui_tool </p></figcaption></figure>

* Arm the vehicle&#x20;

Arm the vehicle (using QGC or RC transmitter depending on your setup):

<figure><img src="https://2042189127-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M7FJ_hQKd8L0MNgduui%2Fuploads%2FXqZqmYp3nf9MkIfy7AER%2FPicture13.png?alt=media&#x26;token=b3dbb5ba-4457-4d44-a61f-63d382d211bb" alt=""><figcaption><p>dronecan_gui_tool </p></figcaption></figure>

### External links:

\[1] [GitHub pull request](https://github.com/PX4/PX4-Autopilot/pull/19748/commits/3788cf386008caafcc8a814feae206342174a700)

\[2] <https://github.com/DroneCAN/gui_tool>&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nxp.gitbook.io/ucans32k1/ucans32k1sic-demo-application/demo-uavcan-node-servo-pwm-control.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
