-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RGBカメラによるライントレースの実装 #47
Merged
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
004eac5
カメラによるライントレース用のファイルを作成
YusukeKato 31c1e2a
実行可能な状態に更新
YusukeKato d524acc
ライントレースが実行可能な状態に更新
YusukeKato a607ff5
スイッチ0を押してcmd_velの配信をオンオフできるように変更
YusukeKato b72a1c9
スイッチの処理を修正
YusukeKato a9ad829
colcon testが通るように修正
YusukeKato 125abf2
Copyrightの文面を修正
YusukeKato 1dad0d4
Copyrightの文面を修正
YusukeKato 1fb0729
Copyrightの文面を修正
YusukeKato 52f33a5
使用されていないmsgを削除
YusukeKato 02ed75e
usingをnamespace内で使用するように変更
YusukeKato d8099b5
変数にconstを付ける
YusukeKato 349b400
is_bigendianの行を削除
YusukeKato 4969c4b
内部変数を変更しない関数にconstを付ける
YusukeKato 442878b
ソースコードのほうでもconstを付ける
YusukeKato d8891c0
cmd_velを関数内で宣言する
YusukeKato 445f6db
constをconstexprに変更
YusukeKato e4d4f16
コメントを修正
YusukeKato 48c00f5
スイッチの処理を修正
YusukeKato a1a8154
following()をdetecting_lineに変更
YusukeKato b1b3ceb
検出結果の文字の色を青から白に変更
YusukeKato 8f559e8
コメントを修正
YusukeKato f6067af
返り値をbool型に変更
YusukeKato 5a17a7d
関数にconstを付ける
YusukeKato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
82 changes: 82 additions & 0 deletions
82
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,82 @@ | ||||||
// Copyright 2020 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 can_publish_cmdvel_; | ||||||
cv::Point2d object_normalized_point_; | ||||||
double object_normalized_area_; | ||||||
geometry_msgs::msg::Twist cmd_vel_; | ||||||
raspimouse_msgs::msg::Switches switches_; | ||||||
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(int mat_type); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 内部変数を変えない場合はconstを付けてください。
Suggested change
|
||||||
void convert_frame_to_message( | ||||||
const cv::Mat & frame, | ||||||
sensor_msgs::msg::Image & msg); | ||||||
|
||||||
void following(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 2020 RT Corporation | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# | ||||||
# 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ソースファイルも同様に対応してください。