add camera service
This commit is contained in:
39
src/camera/camera/camera_controller.py
Normal file
39
src/camera/camera/camera_controller.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
|
||||
from drone_services.srv import TakePicture
|
||||
|
||||
from picamera2 import Picamera2
|
||||
|
||||
|
||||
class CameraController(Node):
|
||||
def __init__(self):
|
||||
super().__init__('camera_controller')
|
||||
self.picam2 = Picamera2()
|
||||
self.srv = self.create_service(TakePicture, 'drone/picture', self.take_picture_callback)
|
||||
|
||||
def take_picture_callback(self, request, response):
|
||||
if (request.input_name == "default"):
|
||||
self.get_logger().info("Taking picture with default filename")
|
||||
self.picam2.start_and_capture_file("/home/ubuntu/image.jpg")
|
||||
response.filename = "/home/ubuntu/image.jpg"
|
||||
else:
|
||||
self.picam2.start_and_capture_file(request.input_name)
|
||||
response.filename = request.input_name
|
||||
return response
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
|
||||
test_controller = CameraController()
|
||||
rclpy.spin(test_controller)
|
||||
|
||||
# Destroy the node explicitly
|
||||
# (optional - otherwise it will be done automatically
|
||||
# when the garbage collector destroys the node object)
|
||||
test_controller.destroy_node()
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,18 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||
<package format="3">
|
||||
<name>camera</name>
|
||||
<version>0.0.0</version>
|
||||
<description>TODO: Package description</description>
|
||||
<maintainer email="semmer99@gmail.com">ubuntu</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
<name>camera</name>
|
||||
<version>0.0.0</version>
|
||||
<description>Package for controlling the camera of the drone</description>
|
||||
<maintainer email="semmer99@gmail.com">ubuntu</maintainer>
|
||||
<license>Apache License 2.0</license>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
<exec_depend>rclpy</exec_depend>
|
||||
<exec_depend>drone_services</exec_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
<test_depend>python3-pytest</test_depend>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
||||
3
src/drone_services/srv/TakePicture.srv
Normal file
3
src/drone_services/srv/TakePicture.srv
Normal file
@@ -0,0 +1,3 @@
|
||||
wstring input_name "default" # name of the input file
|
||||
---
|
||||
wstring filename # output file name
|
||||
@@ -1,8 +1,4 @@
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "object_detection/msg/lidar_reading.hpp"
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "rclcpp/rclcpp.hpp"
|
||||
#include "object_detection/msg/multiflex_reading.hpp"
|
||||
|
||||
Submodule src/px4_msgs updated: ffc3a4cd57...b64ef0475c
Reference in New Issue
Block a user