- ROS Package Names:
- weigher
- weigher_interfaces
- ROS Distribution: humble
- Description: This repository contains ROS 2 packages that publish weight messages from a digital scale.
- Version: 1.0.0
- Weigher Package: weigher
- Weigher Node Name: weigher
- Weigher Launch File: weigher_launch.py
- Weigher Messages:
- Weight.msg
- WeightArray.msg
- Weigher Topics:
- /weigher/weight
- /weigher/weight_thresholded
- /weigher/weight_array
- /weigher/weight_array_thresholded
- Weigher Service Files:
- Tare.srv
- Weigher Services:
- /weigher/tare
- Docker Image Name: weigher:humble
- Release Date: 2023-02-16
- Creation Date: 2022-12-14
- License: BSD-3-Clause
- URL: https://github.com/RatCity-Habitat/weigher_ros
- Author: Peter Polidoro
- Email: [email protected]
- Copyright: 2023 Howard Hughes Medical Institute
- References:
- https://github.com/janelia-pypi/loadstar_sensors_interface_python
- Python Dependency List: loadstar_sensors_interface
- Connect weigh scale to Raspberry Pi USB port.
- Connect Raspberry Pi to power and Ethernet.
Scale will be tared on power up and automatically begin publishing weight messages.
On a computer connected to the same network as the Raspberry Pi, either use Docker or install ROS 2 to subscribe to weight messages.
docker run -it --net=host --pid=host weigher:humble ros2 topic list
docker run -it --net=host --pid=host weigher:humble ros2 topic echo /weigher/weight
docker run -it --net=host --pid=host weigher:humble ros2 topic echo /weigher/weight_thresholded
docker run -it --net=host --pid=host weigher:humble ros2 topic echo /weigher/weight_array
docker run -it --net=host --pid=host weigher:humble ros2 topic echo /weigher/weight_array_thresholded
source ~/ros2_ws/install/setup.bash
ros2 topic list
ros2 topic echo /weigher/weight
ros2 topic echo /weigher/weight_thresholded
ros2 topic echo /weigher/weight_array
ros2 topic echo /weigher/weight_array_thresholded
On a computer connected to the same network as the Raspberry Pi, either use Docker or install ROS 2 to use weigher services.
docker run -it --net=host --pid=host weigher:humble ros2 service list
docker run -it --net=host --pid=host weigher:humble ros2 service call /weigher/tare weigher_interfaces/srv/Tare
source ~/ros2_ws/install/setup.bash
ros2 service list
ros2 service call /weigher/tare weigher_interfaces/srv/Tare
- username: weigher
- password:
# This file is generated automatically from metadata
# File edits may be overwritten!
# Single weight reading.
builtin_interfaces/Time stamp
float64 weight # Measurement of the Weight in grams.
# This file is generated automatically from metadata
# File edits may be overwritten!
# Multiple weight readings.
Weight[] array
Send all messages from the digital scale one at a time along with a timestamp for that measurement.
$ ros2 topic echo /weigher/weight
---
stamp:
sec: 1676470173
nanosec: 765260627
weight: 0.13607771100000002
---
stamp:
sec: 1676470173
nanosec: 883177140
weight: 0.0
---
stamp:
sec: 1676470174
nanosec: 11527425
weight: 0.04535923700000001
---
stamp:
sec: 1676470174
nanosec: 176475007
weight: 0.18143694800000004
---
$ ros2 topic hz /weigher/weight
average rate: 574.719
min: 0.000s max: 0.038s std dev: 0.00568s window: 2338
average rate: 576.536
min: 0.000s max: 0.038s std dev: 0.00566s window: 2922
Send some messages from the digital scale one at a time along with a timestamp for that measurement, if the weight value exceeds a threshold. The threshold value is set with the threshold parameter.
$ ros2 topic echo /weigher/weight_thresholded
---
stamp:
sec: 1676470255
nanosec: 932870887
weight: 520.8601184710001
---
stamp:
sec: 1676470256
nanosec: 19947998
weight: 504.39471544000014
---
stamp:
sec: 1676470256
nanosec: 161346684
weight: 499.8134325030001
---
stamp:
sec: 1676470256
nanosec: 301352968
weight: 498.5887331040001
---
$ ros2 topic hz /weigher/weight_thresholded
average rate: 503.230
min: 0.000s max: 0.054s std dev: 0.00695s window: 5102
average rate: 503.906
min: 0.000s max: 0.054s std dev: 0.00697s window: 5613
Send an array of Weight messages to increase the size and decrease the frequency of messages published on this topic. The maximum array length is set by the weight_array_length_max parameter.
$ ros2 topic echo /weigher/weight_array
---
array:
- stamp:
sec: 1676473446
nanosec: 920160731
weight: 2.0411656650000003
- stamp:
sec: 1676473446
nanosec: 921633371
weight: 2.0411656650000003
- stamp:
sec: 1676473446
nanosec: 922349652
weight: 2.0865249020000003
- stamp:
sec: 1676473446
nanosec: 922925743
weight: 2.0865249020000003
- '...'
---
$ ros2 topic hz /weigher/weight_array
average rate: 0.287
min: 3.460s max: 3.495s std dev: 0.01312s window: 4
average rate: 0.288
min: 3.454s max: 3.495s std dev: 0.01571s window: 5
Send an array of Weight messages to increase the size and decrease the frequency of messages published on this topic. The maximum array length is set by the weight_array_length_max parameter.
Only include weight messages in the array if the weight value exceeds a threshold. The threshold value is set with the threshold parameter.
Do not send empty arrays.
$ ros2 topic echo /weigher/weight_array_thresholded
---
array:
- stamp:
sec: 1676473988
nanosec: 201336549
weight: 491.467332895
- stamp:
sec: 1676473988
nanosec: 202358047
weight: 491.467332895
- stamp:
sec: 1676473988
nanosec: 203483274
weight: 491.467332895
- stamp:
sec: 1676473988
nanosec: 204520182
weight: 491.467332895
- '...'
---
$ ros2 topic hz /weigher/weight_array_thresholded
average rate: 0.251
min: 3.933s max: 4.048s std dev: 0.04806s window: 4
average rate: 0.251
min: 3.933s max: 4.048s std dev: 0.04406s window: 5
# This file is generated automatically from metadata
# File edits may be overwritten!
---
builtin_interfaces/Time stamp
bool success
$ ros2 service call /weigher/tare weigher_interfaces/srv/Tare
requester: making request: weigher_interfaces.srv.Tare_Request()
response:
weigher_interfaces.srv.Tare_Response(stamp=builtin_interfaces.msg.Time(sec=1676492636, nanosec=617772030), success=True)
-
Install Docker
https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
-
Clone this repository
git clone https://github.com/RatCity-Habitat/weigher_ros.git
-
Make Docker image
cd weigher_ros docker build -f .metadata/docker/Dockerfile -t weigher:humble . # or make -f .metadata/Makefile docker-image
-
Install ROS 2
https://docs.ros.org/en/humble/Installation/Ubuntu-Install-Debians.html
-
Create ROS 2 Workspace and clone this repository
mkdir -p ~/ros2_ws/src && \ cd ~/ros2_ws/src && \ git clone https://github.com/RatCity-Habitat/weigher_ros.git
-
Setup Python virtualenv
sudo apt install python3-venv cd ~/ros2_ws make -f src/weigher_ros/.metadata/Makefile virtualenv
-
Build ROS packages
-
Source the ROS underlay and activate the Python virtualenv and build ROS packages
# build may finish with stderr warnings about deprecated setup.py install # if using Python 3.10 or higher cd ~/ros2_ws && \ make -f src/weigher_ros/.metadata/Makefile ros-build
-
-
Setup Raspberry Pi
https://github.com/janelia-experimental-technology/raspberrypi_setup
- username: weigher
- hostname: weigher
-
SSH into Raspberry Pi
-
Web Console
-
Clone Repository
cd ~ && \ git clone [email protected]:RatCity-Habitat/weigher_ros.git
-
Add deploy ssh key to Github Repository
cat .ssh/id_ed25519.pub
-
Install make for metadata commands
sudo apt install make
-
Docker image
cd ~/weigher_ros && \ make -f .metadata/Makefile docker-image
-
Pi Setup
cd ~/weigher_ros && \ make -f .metadata/Makefile pi-setup sudo reboot
-
Check docker and systemd service
systemctl status docker systemctl status [email protected] systemd-analyze plot > boot_analysis.svg docker container list
make -f .metadata/Makefile docker-container
make -f .metadata/Makefile docker-container-port
make -f .metadata/Makefile docker-publish-weight
make -f .metadata/Makefile docker-echo-weight-array
make -f .metadata/Makefile docker-echo-weight-array-thresholded
make -f .metadata/Makefile docker-tare
docker stop $(docker ps -aq)
docker ps
docker exec -it container-name bash
-
Source the ROS underlay and activate the Python virtualenv and build ROS packages
# build may finish with stderr warnings about deprecated setup.py install # if using Python 3.10 or higher cd ~/ros2_ws && \ make -f src/weigher_ros/.metadata/Makefile ros-build
-
Source the ROS underlay and overlay and activate Python virtualenv and run the weigher node
-
Launch file
source ~/ros2_ws/src/weigher_ros/.metadata/setup.bash && \ source ~/ros2_ws/install/setup.bash && \ ros2 launch weigher weigher_launch.py
-
ROS Run
source ~/ros2_ws/src/weigher_ros/.metadata/setup.bash && \ source ~/ros2_ws/install/setup.bash && \ ros2 run weigher weigher
-
-
Echo the weigher topics
# Open a new termial source ~/ros2_ws/install/setup.bash ros2 topic echo /weigher/weight ros2 topic echo /weigher/weight_thresholded ros2 topic echo /weigher/weight_array ros2 topic echo /weigher/weight_array_thresholded
cd ~/weigher_ros
git pull
make -f .metadata/Makefile docker-image
make -f .metadata/Makefile pi-setup
sudo reboot
git clone [email protected]:RatCity-Habitat/weigher_ros.git
make -f .metadata/Makefile metadata-edits
make -f .metadata/Makefile metadata