-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving all ROS1 simulator changes from robosub back here (#3)
- Loading branch information
1 parent
f685e92
commit 8ff7c6f
Showing
24 changed files
with
144 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
descriptions/vortex_descriptions/launch/robosub_world_sub.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<!-- | ||
<!-- | ||
Base code written by Kristoffer Rakstad Solberg, Student | ||
Copyright (c) 2019 Manta AUV, Vortex NTNU. | ||
All rights reserved. --> | ||
|
||
<launch> | ||
<include file="$(find vortex_descriptions)/launch/robosub_world.launch"/> | ||
<include file="$(find urab_sub_description)/launch/upload_urab_sub.launch"/> | ||
<include file="$(find urab_sub_thruster_manager)/launch/thruster_manager.launch"/> | ||
<include file="$(find vortex_descriptions)/launch/robosub_world.launch" pass_all_args="true"/> | ||
<include file="$(find urab_sub_description)/launch/upload_urab_sub.launch" pass_all_args="true"/> | ||
<include file="$(find urab_sub_thruster_manager)/launch/thruster_manager.launch"/> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import rospy | ||
from sensor_msgs.msg import Image | ||
from cv_bridge import CvBridge | ||
|
||
class ImageListener: | ||
""" Abstract class. Subscribes to ROS Image messages. Used for getting camera image data | ||
from the simulator and converting it for OpenCV. """ | ||
|
||
def callback(self, img_msg): | ||
bridge = CvBridge() | ||
# Stores as a BGR array for OpenCV. | ||
cv_image = bridge.imgmsg_to_cv2(img_msg, desired_encoding='bgr8') | ||
self.images.append(cv_image) | ||
|
||
def get_images(self, time): | ||
self.images = [] | ||
rospy.sleep(time) # time is in seconds | ||
return self.images | ||
|
||
def get_images_forever(self): | ||
self.images = [] | ||
rospy.spin() | ||
return self.images | ||
|
||
class FrontCameraListener(ImageListener): | ||
""" Gets image data from the front camera. """ | ||
def __init__(self): | ||
self.subscr = rospy.Subscriber("/urab_sub/urab_sub/camerafront/camera_image", | ||
Image, self.callback) | ||
|
||
class UnderCameraListener(ImageListener): | ||
""" Gets image data from the bottom camera. """ | ||
def __init__(self): | ||
self.subscr = rospy.Subscriber("/urab_sub/urab_sub/cameraunder/camera_image", | ||
Image, self.callback) | ||
|
||
if __name__ == '__main__': | ||
# not sure if this should be moved into the ImageListener class | ||
rospy.init_node('img_listener', anonymous=True) | ||
|
||
front_listen = FrontCameraListener() | ||
imgs = front_listen.get_images(1.0) | ||
|
||
print "FRONT CAMERA" | ||
print "ImageListener.get_images() has type " + str(type(imgs)) | ||
print "Length of image list: " + str(len(imgs)) | ||
print "The first image has type " + str(type(imgs[0])) | ||
print "The first image has dimensions " + str(imgs[0].shape) | ||
print "Print out the first image:" | ||
print imgs[0] | ||
|
||
under_listen = UnderCameraListener() | ||
imgs = under_listen.get_images(1.0) | ||
|
||
print "\n\nBOTTOM CAMERA" | ||
print "ImageListener.get_images() has type " + str(type(imgs)) | ||
print "Length of image list: " + str(len(imgs)) | ||
print "The first image has type " + str(type(imgs[0])) | ||
print "The first image has dimensions " + str(imgs[0].shape) | ||
print "Print out the first image:" | ||
print imgs[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import rospy | ||
import numpy as np | ||
import cv2 | ||
import read_cameras | ||
|
||
def display_camera_images(listener, time, window_name="video"): | ||
"""Displays camera images received from an ImageListener object, which | ||
gets video data for the specified amount of time, in seconds.""" | ||
imgs = listener.get_images(1.0) | ||
for frame in imgs: | ||
cv2.imshow(window_name, frame) | ||
# you need to hold a key to see the video progress. Press q to quit. | ||
if cv2.waitKey(0) & 0xFF == ord('q'): | ||
break | ||
cv2.destroyAllWindows() | ||
|
||
|
||
if __name__ == '__main__': | ||
rospy.init_node('img_listener', anonymous=True) | ||
front_listen = read_cameras.FrontCameraListener() | ||
display_camera_images(front_listen, 1, "front camera") |