Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: RGB Led controlled via ROS #2

Merged
merged 15 commits into from
Apr 13, 2022
Merged

Feature: RGB Led controlled via ROS #2

merged 15 commits into from
Apr 13, 2022

Conversation

acbuynak
Copy link
Member

@acbuynak acbuynak commented Apr 5, 2022

RGB Led onboard an Arduino Uno is controllable via ROS. PR updates Arduino Sketchbook.

Major Updates

  • Reorganize Arduino Sketchbook
  • Add ROS integration to have Arduino listen for a ROS topic to set the RGB led
  • Python code to publish to /paintbrush_color topic

Tests

Launched control to Arduino using roslaunch light_painting t2_led_paintbrush.launch.
Used RQT's Message Publisher to publish test messages and confirmed LED updated to match RGB setting.

image

Design Notes:

Verified Arduino had sufficient buffer size on Arduino Uno. Message is 3xUINT8 values (ie. 3 bytes). Current program size leaves ~600 bytes of memory available for variables. This is sufficient.

Program Control Flow:

flowchart_RGB_ROS_control

Remaining Work

Mohammad Khan and others added 8 commits April 4, 2022 16:43
- still using Serial Connection --> should consider moving to ROS publisher for RGB. Can publish an array of the RGB values and send that to the Arduino script to input the values to the RGB
- Will test on 4/4
- Need to use nested For loop to go through all RGB image values
- Might need to do a ROS connection. Publish the RGB values read from the image to the arduino script rather than serial connection
- Already able to read pixel values using img[0][0] command
- NEXT: How to send the pixel data to the Arduino
Serial Connection tutorials aren't clear on how to send multiple integers to RGB
- Could publish RGB values into a topic then have Arduino script pull that from the rgb topic
* Use `/arduino_control` as Arduino Sketchbook folder for compiling
* Individual files were not reviewed
* add libraries callout
* add libraries .gitignore
* add README.md for arduino controller codes
* Add RGB led control interface. Compiels, but untested on hardware.
* Add custom message for RGB led state
* Update CMakeLists and Package.xml for new message
* add launch file with argument for port
* locked Arduino Baud rate at 500,000
@acbuynak acbuynak added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 5, 2022
@acbuynak acbuynak requested a review from MohammadKhan-3 April 5, 2022 15:10
@acbuynak
Copy link
Member Author

acbuynak commented Apr 6, 2022

Next Steps

Setup

1 - Init ROS Node
2 - Setup Publisher to topic /paintbrush_color using custom message type: light_painting/RGBState.msg

Main

3 - Read pixel value < r, g, b >
4 - Instantiate and build a new RGBState message
5 - Set values of message. Must be UINT8 values (0-255)

Pseudo Code

This might look something like this pseudo-ish code.
This is just some relevant chunks, does not include everything needed for a ROS node w/ publisher. This will not run.

import rospy
from light_painting.msg import RGBState

pub = rospy.Publisher('paintbrush_color ', RGBState, queue_size=5)

msg = RGBState()
msg.red = 187
msg.green = 0
msg.blue = 0

pub.publish(msg)

MohammadKhan-3 and others added 6 commits April 6, 2022 10:52
- USE RGB_values_publisher to test the publisher
- Added nested for loop to RGB_no_descartes script
- NEED TO TEST IF ARDUINO READS THE RGB VALUES SENT FROM PUBLISHER
-Keep losing sync with arduino 
-have not successfully used rgb publisher in robot_motion script
To launch: just run light_painting.launch. it already initializes the ARduino connection. 
- Added Block O RGB
- Occasionally gets Timeout for Trajectory motion for large images (10x10)
- Removed comments, notes, unused variables in RGB_no_descartes script
- Added grayscale images for next feature
* reformat
* remove extra scraps and notes
Copy link
Member Author

@acbuynak acbuynak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the commits! Overall, this looks pretty good. I made a few suggestions and requested a few changes to help overall clarity of the code. Comments are here as well as scattered throughout the code.
Please make those changes and then this should be ready. Changes can just be pushed to the same branch again.

General Comments:

  • Suggest removing extra image files that are not directly used by the project.
  • Please improve naming convention for python scripts or provide a README. The multiple py_to_ino... and no_descartes... scripts are confusing.
  • Unclear which file is the main file to start. No ros .launch file to automatically select the correct file either.

launch/light_painting.launch Show resolved Hide resolved
.gitignore Show resolved Hide resolved
@@ -11,7 +11,7 @@
BINARY = join(RESOURCES,'binary') # combine image folder location with binary
# print('Binary Directory:',BINARY)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra print() statements that were used for original debugging.

Comment on lines +32 to +33
# BGR = cv2.imread(join(R_G_B,blockO_rgb))
# RGB = cv2.cvtColor(BGR,cv2.COLOR_BGR2RGB)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only keep a single line that's being run. Don't duplicate.
This is convenient when doing your own debugging/testing, but shouldn't be kept in final version.

Remove this and other duplicated & commented out sections (ie. the above blockO_rgb line as well).

Comment on lines 23 to 24
# arduino = serial.Serial(port='/dev/ttyACM0',baudrate=9600,timeout=0.1)
# Code from: https://www.electronicshub.org/controlling-arduino-led-python/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all serial commands from script since we're using the roslaunch & rosserial package to communicate with Arduino.

Comment on lines +37 to +45
# print('Size of RGB: ',rgb_img.size)
# print('rgb_img[0,0] pixel 1 value:',rgb_img[0,0])
# print('rgb_img.item(0) pixel 1 value:',rgb_img.item(0)) # gets only the 1st value
# print('rgb_img[0,0] pixel 4 value(mid pixel):',rgb_img[1,1])
# print('rgb_img[0,0] pixel 8 value(bottom right):',rgb_img[2,2])
# red,green,blue = rgb_img[1,1]
# print('Red value of pixel 4:',red)
# print('Green value of Pixel 4:',green)
# print('Blue value of pixel 4:',blue)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this block of print statements. Not used by the actual code.
Not helpful for debugging.

Suggest adding a sentence or two explaining what this function does, you already kind of have it with the top comment "Testing reading values....". Maybe just add what the input value needs to be and what the function returns.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment about the specific order of RGB vs BGR may be good to include since you mention it a few lines below as well.

Comment on lines +77 to +98
class RGB_publisher():
def __init__(self,rgb_values):
self.rgb_values = rgb_values
def runner(self,data):
try:
rgb_values = [0,0,0]
rgb_img = input_image.rgb


r,g,b = RGB_values(rgb_img)
data = (r,g,b)

rgb_values.data = list(bytearray(data))

self.rgb_values.publish(rgb_values)
rospy.loginfo(rgb_values)


except rospy.ROSInterruptException:
exit()
except KeyboardInterrupt:
exit()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't understand why class is at the bottom of the file.
Suggest moving above main() function to more consistently organize code like other python scripts.

scripts/py_to_ino_RGB_LED_test.py Outdated Show resolved Hide resolved
print('Keep moving horizontally')
waypoints = nextColumn(wpose)

# input(f"Cartesian Plan {i}: press <enter>") # uncomment this line if you want robot to run automatically
Copy link
Member Author

@acbuynak acbuynak Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment as was used for debugging and would not be used in final code.

Comment on lines +113 to +118
plan, fraction = rc.plan_cartesian_path(waypoints)
rc.execute_plan(plan)
sendRGB2LED(pub_rgb_values,r,g,b)
time.sleep(0.5)
sendRGB2LED(pub_rgb_values)
time.sleep(0.5)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding a comment on why send value, sleep, then send again.
The practical function of these lines of code are vague, but critical to operation of this script. Add documentation.

* gitignore all .pyc files
* misc code formatting
* remove extra/unused imports
@acbuynak
Copy link
Member Author

acbuynak commented Apr 8, 2022

@MohammadKhan-3 Left a review of code. See comments in the review. Once changes made, I think this is ready to merge.
Let's do a regular Merge Pull Request on this one to maintain the commit history.

@MohammadKhan-3
Copy link
Contributor

Built the rosserial_arduino library

I ran rosrun rosserial_arduino serial_node.py -port=/tty/ACM0 -baud=500000
but still getting this error:

[ERROR] [1649688048.164270]: Error opening serial: [Errno 2] could not open port -port=/tty/ACM0: [Errno 2] No such file or directory: '-port=/tty/ACM0'

To create the Binary publisher:

  • made a custom msg type & added Binary_values_publisher script (similar structure to RGB)

@acbuynak
Copy link
Member Author

Rolled back three commits to have this PR only include RGB. Moving Greyscale feature onto a new branch following this PR.

@acbuynak acbuynak merged commit f905f8f into noetic Apr 13, 2022
@acbuynak acbuynak deleted the feature/rgb-led branch April 18, 2022 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants