This package provides a ROS 2 node for interfacing with the AS5048A encoder via SPI on a Raspberry Pi. The node publishes encoder data to various ROS topics.
Tested on:
- Raspberry Pi 4B, Raspberry Pi CM4
- Ubuntu 22.04, ROS2 Humble
- Reads data from the AS5048A encoder over SPI.
- Publishes raw angle and cumulative angle to ROS topics.
This package depends on several ROS 2 packages and the spidev
Python package.
rclpy
std_msgs
spidev
-
Ensure ROS 2 is installed on your Raspberry Pi. You can follow the official ROS 2 installation guide.
-
Install ROS 2 Python dependencies:
sudo apt update sudo apt install ros-humble-rclpy ros-humble-std-msgs
-
Install
spidev
for Python:sudo apt install python3-pip sudo pip3 install spidev
-
Clone the repository into your ROS 2 workspace:
cd ~/ros2_ws/src git clone https://github.com/atarbabgei/ros2_rpi_as5048a.git
-
Build the package:
cd ~/ros2_ws colcon build
-
Source the setup file to overlay the new package into your environment:
source install/setup.bash
Ensure that the AS5048A is running in 3.3V mode. Connecting the AS5048A to 5V mode may damage the Raspberry Pi. Verify the jumper settings or power connections on the AS5048A to make sure it operates at 3.3V.
AS5048A Pin | Raspberry Pi Pin |
---|---|
VCC | Pin 1 or Pin 17 (3.3V) |
GND | Pin 6 (GND) or any other GND pin |
MOSI | GPIO 10 (SPI0 MOSI) |
MISO | GPIO 9 (SPI0 MISO) |
SCK | GPIO 11 (SPI0 SCLK) |
CS | GPIO 8 (SPI0 CE0) |
If using Ubuntu 22.04 OS, make sure SPI is enabled in config.txt
:
dtparam=spi=on
Or if using Raspberry Pi OS:
sudo raspi-config
Navigate to Interfacing Options
> SPI
and enable it.
Run the node using the launch file:
ros2 launch ros2_rpi_as5048a encoder.launch.py
encoder_resolution
(float): The resolution of the AS5048A encoder.
-
/encoder_absolute_angle
(std_msgs/Float32
): The absolute angle in radians (between 0 to$2\pi$ ). -
/encoder_cumulative_angle
(std_msgs/Float32
): The cumulative angle in radians. -
/encoder_angular_velocity
(std_msgs/Float32
): The angular velocity in rads/s.
MIT