Skip to content

Commit

Permalink
initial commit (fix for extermination node)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishaan-Datta committed Nov 9, 2024
1 parent 5b6e220 commit ea846b2
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ if(BUILD_TESTING)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
ament_package()
2 changes: 1 addition & 1 deletion workspace_python/ros2_ws/src/custom_interfaces/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
</package>
1 change: 0 additions & 1 deletion workspace_python/ros2_ws/src/python_workspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,3 @@ To view the image topic :
2. click refresh topic
3. select the name of the image topic you want to see


Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ def generate_launch_description():
{'precision': LaunchConfiguration('precision')}
]
),
])
])
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ def generate_launch_description():
{'precision': LaunchConfiguration('precision')}
]
),
])
])

This file was deleted.

124 changes: 0 additions & 124 deletions workspace_python/ros2_ws/src/python_workspace/launch/old_launch.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from sensor_msgs.msg import Image
from custom_interfaces.msg import InferenceOutput # CHANGE
from .scripts.utils import ModelInference
from std_msgs.msg import String # Example message type

# cuda.init()
# device = cuda.Device(0)
Expand All @@ -24,7 +23,7 @@
class ExterminationNode(Node):
def __init__(self):
super().__init__('extermination_node')

self.declare_parameter('use_display_node', True)
# self.declare_parameter('lower_range', [78, 158, 124]) #todo: make this a parameter
# self.declare_parameter('upper_range', [60, 255, 255])
Expand All @@ -49,24 +48,26 @@ def __init__(self):
# side_topic = 'right_array_data'
# if self.use_display_node:
# self.window = "Right Camera"

self.boxes_present = 0
self.window = "Left Camera"
self.model = ModelInference()
self.bridge = CvBridge()
# Open serial port to Arduino
self.ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1)
self.subscription = self.create_subscription(InferenceOutput, 'inference_out', self.inference_callback, 10)


# Create a timer that calls the listener_callback every second
self.timer = self.create_timer(1.0, self.timer_callback)


self.subscription = self.create_subscription(InferenceOutput, 'inference_out', self.inference_callback, 10)
time.sleep(2) # Wait for Arduino to reset


def inference_callback(self, msg):
preprocessed_image = self.bridge.imgmsg_to_cv2(msg.preprocessed_image, desired_encoding='passthrough')
raw_image = self.bridge.imgmsg_to_cv2(msg.raw_image, desired_encoding='passthrough')


bounding_boxes = self.model.postprocess(msg.confidences.data,msg.bounding_boxes.data, raw_image,msg.velocity)

final_image = self.model.draw_boxes(raw_image,bounding_boxes,velocity=msg.velocity)
Expand All @@ -87,6 +88,7 @@ def timer_callback(self):
self.ser.write(serialized_msg.encode())
self.get_logger().info(f'Sent to Arduino: {self.boxes_present}')


def main(args=None):
rclpy.init(args=args)
extermination_node = ExterminationNode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class PictureNode(Node):
def __init__(self):
super().__init__('picture_node')

self.declare_parameter('static_image_path', '/home/user/ROS/assets/maize/IMG_1822_14.JPG')
self.declare_parameter('static_image_path', '/home/usr/Desktop/ROS/assets/IMG_1822_14.JPG')
self.declare_parameter('loop', 0) # 0 = don't loop, >0 = # of loops, -1 = loop forever
self.declare_parameter('frame_rate', 1) # Desired frame rate for publishing


self.static_image_path = self.get_parameter('static_image_path').get_parameter_value().string_value
# Resolve the path programmatically
Expand Down

0 comments on commit ea846b2

Please sign in to comment.