Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 28 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,31 @@
# 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 <Name>, <Roll No.>```. 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.

**Edit:** Create a launch file named ```image_cropping.launch``` which launches all the nodes at once.
ASSIGNMENT-1
#create a catkin workspace
mkdir catkin_ws
cd catkin_ws
mkdir src
catkin_make
cdc
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
=======
53 changes: 53 additions & 0 deletions node1.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions node123.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<launch>

<node pkg="image_processes" name="node1" type="node1.py">
</node>
<node pkg="image_processes" name="node2" type="node2.py">
</node>
<node pkg="image_processes" name="node3" type="node3.py">
</node>
</launch>
44 changes: 44 additions & 0 deletions node2.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions node3.py
Original file line number Diff line number Diff line change
@@ -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