<repo_name>frankjoshua/docker-ros-encoders<file_sep>/node.py
#!/usr/bin/env python
import rospy
import serial
import os
from std_msgs.msg import Int32

ROS_NODE = os.getenv('ROS_NODE')

def encoder():
    leftWheel = rospy.Publisher('left_wheel', Int32, queue_size=0)
    rightWheel = rospy.Publisher('right_wheel', Int32, queue_size=0)
    rospy.init_node(ROS_NODE)
    ser = serial.Serial('/dev/ttyACM0', 115200, timeout=.2)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        # make sure serial data is clean
        ser.flushInput()
        ser.readline()
        # read data
        line = ser.readline()[:-2].decode('utf-8')
        # Publish data
        data = line.split(",")
        leftWheel.publish(int(data[0]))
        rightWheel.publish(int(data[1]))
        rate.sleep()

if __name__ == '__main__':
    try:
        encoder()
    except rospy.ROSInterruptException:
        pass<file_sep>/README.md
# ROS encoders in Docker [![](https://img.shields.io/docker/pulls/frankjoshua/ros-encoders)](https://hub.docker.com/r/frankjoshua/ros-encoders) [![Build Status](https://travis-ci.org/frankjoshua/docker-ros-encoders.svg?branch=master)](https://travis-ci.org/frankjoshua/docker-ros-encoders)

## Description

Publishes topics:<br>
/left_wheel (Int32)<br>
/right_wheel (Int32)<br>
Parses CSV output from an Arduino over serial<br>
Example Arduino Code:<br>
[https://github.com/frankjoshua/arduino-dual-ls7366r](https://github.com/frankjoshua/arduino-dual-ls7366r)

## Example

```
docker run -it \
    --network="host" \
    --env="ROS_IP=$ROS_IP" \
    --env="ROS_MASTER_URI=$ROS_MASTER_URI" \
    --device "/dev/ttyACM1:/dev/ttyACM0"
    frankjoshua/ros-encoders
```

## Testing

Travis CI expects the DOCKER_USERNAME and DOCKER_PASSWORD variables to be set in your environment.

## License

Apache 2.0

## Author Information

<NAME> [@frankjoshua77](https://www.twitter.com/@frankjoshua77)
<br>
[http://roboticsascode.com](http://roboticsascode.com)
<file_sep>/Dockerfile
FROM ros:noetic-ros-base

RUN apt-get update &&\
  apt-get install -y python3-pip &&\
  apt-get -y clean &&\
  apt-get -y purge &&\
  rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN python3 -m pip install pyserial

COPY node.py /

ENV ROS_NODE=encoders

HEALTHCHECK CMD /ros_entrypoint.sh rosnode info $ROS_NODE || exit 1

CMD ["python3", "/node.py"]