-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* カメラによるライントレース用のファイルを作成 * 実行可能な状態に更新 * ライントレースが実行可能な状態に更新 * スイッチ0を押してcmd_velの配信をオンオフできるように変更 * スイッチの処理を修正 * colcon testが通るように修正 * Copyrightの文面を修正 Co-authored-by: Shota Aoki <[email protected]> * Copyrightの文面を修正 Co-authored-by: Shota Aoki <[email protected]> * Copyrightの文面を修正 Co-authored-by: Shota Aoki <[email protected]> * 使用されていないmsgを削除 Co-authored-by: Shota Aoki <[email protected]> * usingをnamespace内で使用するように変更 * 変数にconstを付ける * is_bigendianの行を削除 * 内部変数を変更しない関数にconstを付ける Co-authored-by: Shota Aoki <[email protected]> * ソースコードのほうでもconstを付ける * cmd_velを関数内で宣言する * constをconstexprに変更 Co-authored-by: Shota Aoki <[email protected]> * コメントを修正 * スイッチの処理を修正 * following()をdetecting_lineに変更 * 検出結果の文字の色を青から白に変更 * コメントを修正 Co-authored-by: Shota Aoki <[email protected]> * 返り値をbool型に変更 * 関数にconstを付ける --------- Co-authored-by: Shota Aoki <[email protected]>
- Loading branch information
1 parent
f35d35a
commit 153c25c
Showing
4 changed files
with
456 additions
and
0 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
80 changes: 80 additions & 0 deletions
80
include/raspimouse_ros2_examples/camera_line_follower_component.hpp
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,80 @@ | ||
// Copyright 2023 RT Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef RASPIMOUSE_ROS2_EXAMPLES__CAMERA_LINE_FOLLOWER_COMPONENT_HPP_ | ||
#define RASPIMOUSE_ROS2_EXAMPLES__CAMERA_LINE_FOLLOWER_COMPONENT_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "raspimouse_msgs/msg/switches.hpp" | ||
#include "raspimouse_ros2_examples/visibility_control.h" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "rclcpp_lifecycle/lifecycle_node.hpp" | ||
#include "rclcpp_lifecycle/lifecycle_publisher.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
#include "std_srvs/srv/set_bool.hpp" | ||
#include "sensor_msgs/msg/image.hpp" | ||
#include "geometry_msgs/msg/twist.hpp" | ||
#include "opencv2/highgui/highgui.hpp" | ||
|
||
namespace camera_line_follower | ||
{ | ||
|
||
class Camera_Follower : public rclcpp_lifecycle::LifecycleNode | ||
{ | ||
public: | ||
RASPIMOUSE_ROS2_EXAMPLES_PUBLIC | ||
explicit Camera_Follower(const rclcpp::NodeOptions & options); | ||
|
||
protected: | ||
void image_callback(const sensor_msgs::msg::Image::SharedPtr msg_image); | ||
void callback_switches(const raspimouse_msgs::msg::Switches::SharedPtr msg); | ||
void on_cmd_vel_timer(); | ||
|
||
private: | ||
cv::VideoCapture cap_; | ||
bool object_is_detected_; | ||
bool enable_following_; | ||
cv::Point2d object_normalized_point_; | ||
double object_normalized_area_; | ||
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<sensor_msgs::msg::Image>> result_image_pub_; | ||
std::shared_ptr<rclcpp_lifecycle::LifecyclePublisher<geometry_msgs::msg::Twist>> cmd_vel_pub_; | ||
std::shared_ptr<rclcpp::Client<std_srvs::srv::SetBool>> motor_power_client_; | ||
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr image_sub_; | ||
rclcpp::Subscription<raspimouse_msgs::msg::Switches>::SharedPtr switches_sub_; | ||
rclcpp::TimerBase::SharedPtr cmd_vel_timer_; | ||
|
||
std::string mat_type2encoding(const int mat_type) const; | ||
void convert_frame_to_message( | ||
const cv::Mat & frame, | ||
sensor_msgs::msg::Image & msg) const; | ||
|
||
bool detecting_line(const cv::Mat & input_frame, cv::Mat & result_frame); | ||
|
||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
on_configure(const rclcpp_lifecycle::State &); | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
on_activate(const rclcpp_lifecycle::State &); | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
on_deactivate(const rclcpp_lifecycle::State &); | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
on_cleanup(const rclcpp_lifecycle::State &); | ||
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn | ||
on_shutdown(const rclcpp_lifecycle::State &); | ||
}; | ||
|
||
} // namespace camera_line_follower | ||
|
||
#endif // RASPIMOUSE_ROS2_EXAMPLES__CAMERA_LINE_FOLLOWER_COMPONENT_HPP_ |
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,90 @@ | ||
# Copyright 2023 RT Corporation | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import launch | ||
from launch.actions import DeclareLaunchArgument | ||
from launch.substitutions import LaunchConfiguration | ||
from launch.conditions import IfCondition | ||
from launch_ros.actions import ComposableNodeContainer | ||
from launch_ros.actions import Node | ||
from launch_ros.descriptions import ComposableNode | ||
|
||
|
||
def generate_launch_description(): | ||
declare_mouse = DeclareLaunchArgument( | ||
'mouse', | ||
default_value="true", | ||
description='Launch raspimouse node' | ||
) | ||
declare_use_camera_node = DeclareLaunchArgument( | ||
'use_camera_node', | ||
default_value='true', | ||
description='Use camera node.' | ||
) | ||
declare_video_device = DeclareLaunchArgument( | ||
'video_device', | ||
default_value='/dev/video0', | ||
description='Set video device.' | ||
) | ||
|
||
"""Generate launch description with multiple components.""" | ||
container = ComposableNodeContainer( | ||
name='camera_line_follower_container', | ||
namespace='', | ||
package='rclcpp_components', | ||
executable='component_container_mt', | ||
composable_node_descriptions=[ | ||
ComposableNode( | ||
package='raspimouse_ros2_examples', | ||
plugin='camera_line_follower::Camera_Follower', | ||
name='camera_follower', | ||
extra_arguments=[{'use_intra_process_comms': True}]), | ||
ComposableNode( | ||
package='raspimouse', | ||
plugin='raspimouse::Raspimouse', | ||
name='raspimouse', | ||
parameters=[{'use_light_sensors': False}], | ||
extra_arguments=[{'use_intra_process_comms': True}], | ||
condition=IfCondition(LaunchConfiguration('mouse'))), | ||
ComposableNode( | ||
package='usb_cam', | ||
plugin='usb_cam::UsbCamNode', | ||
name='usb_cam', | ||
remappings=[('image_raw', 'camera/color/image_raw')], | ||
parameters=[ | ||
{'video_device': LaunchConfiguration('video_device')}, | ||
{'frame_id': 'camera_color_optical_frame'}, | ||
{'pixel_format': 'yuyv2rgb'} | ||
], | ||
extra_arguments=[{'use_intra_process_comms': True}], | ||
condition=IfCondition(LaunchConfiguration('use_camera_node'))), | ||
], | ||
output='screen', | ||
) | ||
|
||
manager = Node( | ||
name='manager', | ||
package='raspimouse_ros2_examples', | ||
executable='lifecycle_node_manager', | ||
output='screen', | ||
parameters=[{'components': ['raspimouse', 'camera_follower']}] | ||
) | ||
|
||
return launch.LaunchDescription([ | ||
declare_mouse, | ||
declare_use_camera_node, | ||
declare_video_device, | ||
container, | ||
manager | ||
]) |
Oops, something went wrong.