Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mcgill-robotics/rover into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
amotaouakkil123 committed May 11, 2024
2 parents 83d8ce6 + 84d8557 commit 9673e55
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 61 deletions.
2 changes: 1 addition & 1 deletion angular_ui_app/src/app/components/drive/drive.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class DriveComponent {

this.gamepadService.connectControllerGamepad(
(input_dir: { [key: string]: number | boolean }) => {
this.gamepad_drive_pub.publish({data: [input_dir['a2'], input_dir['a4']]});
this.gamepad_drive_pub.publish({data: [-input_dir['a2'], -input_dir['a4']]});

if (input_dir['up']) {
this.pantilt_pitch = this.clamp(this.pantilt_pitch + this.angle_delta);
Expand Down
4 changes: 2 additions & 2 deletions angular_ui_app/src/app/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class AppConstants {
// public static get HOST_IP(): string { return '192.168.1.69'; }
public static get HOST_IP(): string { return '192.168.1.69'; }
// public static get HOST_IP(): string { return '10.122.8.160'; }
public static get HOST_IP(): string { return 'localhost'; }
// public static get HOST_IP(): string { return 'localhost'; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
<div>
<app-camera camera_size="large"/>
<!-- <app-backup-camera cameraTopic="/camera_frames" /> -->
<app-drive-component/>
</div>

Expand Down
82 changes: 25 additions & 57 deletions camera_data/src/camera_publisher.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,29 @@
#!/usr/bin/env python3
import os, sys
from pydoc_data.topics import topics
#!/usr/bin/env python

currentdir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(currentdir)
import rospy
import cv2
import time
from cv_bridge import CvBridge
from sensor_msgs.msg import Image
from std_msgs.msg import Int16
from PyQt5 import QtGui
import sys

stop = False

class Node_CameraFramePub():

def __init__(self):
self.frames = None
self.video_capture = cv2.VideoCapture(0, cv2.CAP_V4L2)
self.video_capture.open(0)

rospy.init_node('camera_frame_publisher')
self.camera_select_subscriber = rospy.Subscriber("camera_selection", Int16, self.select_camera)
self.timer = rospy.Timer(rospy.Duration(0.03), self.timer_callback)
self.camera_frame_publisher = rospy.Publisher('/camera_frames', Image, queue_size=10)

def timer_callback(self, event):
try:
ret, frame = self.video_capture.read()
# these code cause error
encode_params = [int(cv2.IMWRITE_JPEG_QUALITY), 90]
result, frame = cv2.imencode(".jpg", frame, encode_params)
self.frames = self.openCV_to_ros_image(frame)
if ret:
print("Publishing frame")
self.camera_frame_publisher.publish(self.frames)
except:
print("No camera found")
finally:
pass

def openCV_to_ros_image(self, cv_image):
try:
bridge = CvBridge()
ros_image = bridge.cv2_to_imgmsg(cv_image, encoding="passthrough")
return ros_image
except:
print("Cannot translate image correctly")

def select_camera(self, x):
self.video_capture.release()
self.video_capture.open(x.data * 2)
print(x.data)

from cv_bridge import CvBridge
import cv2

if __name__ == "__main__":
driver = Node_CameraFramePub()
rospy.spin()
def webcam_publisher():
rospy.init_node('webcam_publisher', anonymous=True)
pub = rospy.Publisher('camera_frames', Image, queue_size=10)
rate = rospy.Rate(30) # 10hz

cap = cv2.VideoCapture(0) # Open the first webcam
bridge = CvBridge()

while not rospy.is_shutdown():
ret, frame = cap.read()
if ret:
# Convert the frame to ROS format
ros_image = bridge.cv2_to_imgmsg(frame, "bgr8")
# Publish the frame
pub.publish(ros_image)
rate.sleep()

if __name__ == '__main__':
try:
webcam_publisher()
except rospy.ROSInterruptException:
pass
1 change: 0 additions & 1 deletion camera_data/src/camera_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self):

def display_frames(self, frame):
self.frames = self.ros_to_openCV_image(frame)
self.frames = cv2.imdecode(self.frames, 1)
print(self.frames.shape)
cv2.imshow("Live Feed", self.frames)
cv2.waitKey(10) # Look into to reduce latency
Expand Down
Loading

0 comments on commit 9673e55

Please sign in to comment.