-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6180c0a
commit 91aa1a3
Showing
2 changed files
with
55 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
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,51 @@ | ||
use rclrs::{Context, Node, Publisher, Subscription, QOS_PROFILE_DEFAULT}; | ||
use std::env; | ||
use std::sync::Arc; | ||
|
||
#[allow(unused)] | ||
struct Mimic { | ||
output_nh: Arc<Node>, | ||
input_nh: Arc<Node>, | ||
twist_pub: Arc<Publisher<geometry_msgs::msg::Twist>>, | ||
pose_sub: Arc<Subscription<turtlesim_rs_msgs::msg::Pose>>, | ||
} | ||
|
||
impl Mimic { | ||
fn new() -> Self { | ||
let context = Context::new(env::args()).unwrap(); | ||
let output_nh = rclrs::create_node(&context, "output").unwrap(); | ||
|
||
let twist_pub = output_nh | ||
.create_publisher("/output/cmd_vel", QOS_PROFILE_DEFAULT) | ||
.unwrap(); | ||
|
||
let input_nh = rclrs::create_node(&context, "input").unwrap(); | ||
|
||
let twist_pub_clone = Arc::clone(&twist_pub); | ||
let pose_sub = input_nh | ||
.create_subscription( | ||
"/input/pose", | ||
QOS_PROFILE_DEFAULT, | ||
move |pose_msg: turtlesim_rs_msgs::msg::Pose| { | ||
let mut twist_msg = geometry_msgs::msg::Twist::default(); | ||
twist_msg.linear.x = pose_msg.linear_velocity as f64; | ||
twist_msg.angular.z = pose_msg.angular_velocity as f64; | ||
twist_pub_clone.publish(twist_msg).unwrap(); | ||
}, | ||
) | ||
.unwrap(); | ||
|
||
Self { | ||
output_nh, | ||
input_nh, | ||
twist_pub, | ||
pose_sub, | ||
} | ||
} | ||
} | ||
|
||
fn main() -> Result<(), rclrs::RclrsError> { | ||
let mimic = Mimic::new(); | ||
rclrs::spin(mimic.input_nh.clone())?; | ||
Ok(()) | ||
} |