From 420efec508960c9ca6b6cbdf6dea4f4eb8a08f65 Mon Sep 17 00:00:00 2001 From: riyaadi <135017030+riyaadi@users.noreply.github.com> Date: Tue, 30 May 2023 16:03:07 +0530 Subject: [PATCH 1/3] Assignment - 1 --- node1.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ node2.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ node3.py | 27 +++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 node1.py create mode 100644 node2.py create mode 100644 node3.py diff --git a/node1.py b/node1.py new file mode 100644 index 0000000..cab28f6 --- /dev/null +++ b/node1.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import rospy +from sensor_msgs.msg import Image +from cv_bridge import CvBridge +import cv2 + +def node1(): + rospy.init_node('node1', anonymous=True) + rate = rospy.Rate(10) # 10 Hz + + pub = rospy.Publisher('Webcam_img', Image, queue_size=10) + bridge = CvBridge() + + while not rospy.is_shutdown(): + # Capture image frames from webcam + image_frame = capture_image_from_webcam() + + # Convert the image to a ROS message + ros_image = bridge.cv2_to_imgmsg(image_frame, encoding='bgr8') + + # Publish the image frame + pub.publish(ros_image) + rate.sleep() + +def capture_image_from_webcam(): + # Open the webcam (usually with device index 0) + cap = cv2.VideoCapture(0) + cv2.waitKey(0) + + # Check if the webcam is successfully opened + if not cap.isOpened(): + print("Failed to open the webcam") + return None + + # Capture frames from the webcam + ret, frame = cap.read() + + # Release the webcam + cap.release() + + # Check if the frame is captured successfully + if not ret: + print("Failed to capture frame from the webcam") + return None + + return frame + +if __name__ == '__main__': + try: + node1() + except rospy.ROSInterruptException: + pass diff --git a/node2.py b/node2.py new file mode 100644 index 0000000..78721c5 --- /dev/null +++ b/node2.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +import cv2 +from cv_bridge import CvBridge +import rospy +from sensor_msgs.msg import Image +pub = rospy.Publisher('Webcam_cropped', Image, queue_size=10) +def node2(): + rospy.init_node('node2', anonymous=True) + rate = rospy.Rate(10) # 10 Hz + + + rospy.Subscriber('Webcam_img', Image, process_image_callback) + + while not rospy.is_shutdown(): + rate.sleep() + +def process_image_callback(image_frame): + # Crop the image frame by 30% in pixels + cv_bridge = CvBridge() + cv_image = cv_bridge.imgmsg_to_cv2(image_frame, desired_encoding='bgr8') + + height, width = cv_image.shape[:2] + new_width = int(width*0.7) + new_height = int(height*0.7) + start_x = int((width - new_width) / 2) + start_y = int((height - new_height) / 2) + cropped_image = cv_image[start_y:start_y + new_height, start_x:start_x + new_width] + image_frame= cv_bridge.cv2_to_imgmsg(cropped_image, encoding='bgr8') + + # Publish the cropped image + pub.publish(image_frame) + +#def crop_image(image): + + # Crop the image by 30% in pixels using appropriate image processing libraries + # Return the cropped image + +if __name__ == '__main__': + try: + node2() + + + except rospy.ROSInterruptException: + pass \ No newline at end of file diff --git a/node3.py b/node3.py new file mode 100644 index 0000000..8852e30 --- /dev/null +++ b/node3.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import rospy +from sensor_msgs.msg import Image +from cv_bridge import CvBridge +import cv2 + +def node3(): + rospy.init_node('node3', anonymous=True) + rospy.Subscriber('Webcam_cropped', Image, show_image_callback) + + rospy.spin() + +def show_image_callback(image_frame): + # Convert the ROS image message to OpenCV format + cv_bridge = CvBridge() + cv_image = cv_bridge.imgmsg_to_cv2(image_frame, desired_encoding='bgr8') + + # Display the image using OpenCV (you may need to adjust the window name) + cv2.imshow('Webcam_cropped', cv_image) + cv2.waitKey(1) # Refresh the display + +if __name__ == '__main__': + try: + node3() + except rospy.ROSInterruptException: + pass \ No newline at end of file From 8017179fa51dce8ab02fd2f80d788c714971f794 Mon Sep 17 00:00:00 2001 From: riyaadi <135017030+riyaadi@users.noreply.github.com> Date: Tue, 30 May 2023 17:55:47 +0530 Subject: [PATCH 2/3] README.md --- README.md | 76 ++++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index fa5647c..231132f 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,30 @@ # SIV-ROS Submissions **Sensor Integration and Visualisation in ROS** -Submission repository for assignments of SIV-ROS project of Robotics Club 2023-24. - -## Objective - -- Introduce and familiarise mentees with ROS, Gazebo and Rviz -- Integrate the following in ROS: - - Motor Encoders for Odometry data - - LiDAR for SLAM (RPLiDAR A1M8 360 Degree) - - IMU (MPU6050) - - GPS (NEO-M8N GPS Module) -- **Simultaneously** take input from the sensors and visualise all the data in Rviz. -- Use teleop through ssh or use another kind of remote control along with gmapping node to use SLAM for creating the map of an environment in Rviz. - -### Folder Structure - -```bash - -SIV-ROS-Submissions -├── Assignment-1 -│ ├── 210353_DivyaGupta -│ │ ├── README.md -│   │ └── src -│ ├── 210369_EmaadAhmed -│   │ ├── README.md -│   │ └── src -│ └── 210684_OmShivamVerma -│   ├── README.md -│   └── src -├── LICENSE -└── README.md - -``` - -#### How to Submit - -Create a **fork** of this repository. This fork is where you will add all the solutions of your assignments. After creating your fork, and making some changes (your solutions), create a pull request with the title: ```Submission of , ```. This pull request should be created only once, - -Here ```src``` is the _source_ folder of your workspace. Also, create the ```README.md``` containing a brief description of what you have done. - -## Assignment-1 - -**Aim:** Understanding nodes, topics, and their connection with sensors. - -**Task:** -Create a package - “Image_processes” that can subscribe and publish topics from given nodes: -1. Node1 -: Publish webcam image frames to the topic “Webcam_img”. (“Webcam_img” topic takes image frames from webcam as data). -2. Node2 -: It will subscribe to the topic “Webcam_img” and publish data to the topic “Webcam_cropped”. (“Webcam_cropped” topic has image frames from webcam and crop it by 30% in pixels). -3. Node3 -: It will subscribe to the topic “Webcam_cropped” and show it. - +ASSIGNMENT-1 +#create a catkin workspace +mkdir catkin_ws +cd catkin_ws +mkdir src +catkin_make +cd +source ~/catkin_ws/devel/setup.bash + +#create a new package "image_processes" +cd ~/catkin_ws/src +catkin_create_pkg image_processes rospy cv2 cv_bridge sensor_msgs + +#create three nodes +cd ~/catkin_ws/src/image_processes +mkdir scripts +cd scripts +touch node1.py +chmod node1.py +touch node2.py +chmod node2.py +touch node3.py +cd ../.. +code . +writing three nodes' code + +run roscore in one terminal and then run three nodes in three terminal windows From bd81e1b509c1fc692aeba2ce8f0ab92d4c16e4d4 Mon Sep 17 00:00:00 2001 From: riyaadi <135017030+riyaadi@users.noreply.github.com> Date: Sat, 10 Jun 2023 21:56:45 +0530 Subject: [PATCH 3/3] adding launch file --- node123.launch | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 node123.launch diff --git a/node123.launch b/node123.launch new file mode 100644 index 0000000..06bd6bd --- /dev/null +++ b/node123.launch @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file