forked from arjo129/rustros_tf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tf_capture outputs a toml of current transforms after looking up tran…
…sforms from an input toml
- Loading branch information
Showing
3 changed files
with
110 additions
and
2 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,68 @@ | ||
use tf_roslibrust::tf_util; | ||
use tf_roslibrust::transforms::tf2_msgs; | ||
|
||
/// Load a toml file of a list of parent/child frames and then find all those transforms in | ||
/// a live system and output a new toml listing of their current values | ||
/// tf_capture examples/transforms.toml > current_transforms.toml | ||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
use roslibrust::ros1::NodeHandle; | ||
|
||
// need to have leading slash on node name and topic to function properly | ||
// so figure out namespace then prefix it to name and topics | ||
let mut ns = String::from(""); | ||
let args = std::env::args(); | ||
let mut args2 = Vec::new(); | ||
{ | ||
// get namespace | ||
for arg in args { | ||
if arg.starts_with("__ns:=") { | ||
ns = arg.replace("__ns:=", ""); | ||
} else { | ||
args2.push(arg); | ||
} | ||
} | ||
} | ||
|
||
let full_node_name = &format!("/{ns}/tf_capture").replace("//", "/"); | ||
// println!("{}", format!("full ns and node name: {full_node_name}")); | ||
|
||
let config_file = &args2[1]; | ||
let tfm = tf_util::get_transforms_from_toml(config_file)?; | ||
|
||
let nh = NodeHandle::new(&std::env::var("ROS_MASTER_URI")?, full_node_name) | ||
.await | ||
.unwrap(); | ||
|
||
print!( | ||
"# {:.3} getting transforms...", | ||
tf_util::stamp_to_f64(tf_util::stamp_now()) | ||
); | ||
let listener = tf_roslibrust::TfListener::new(&nh).await; | ||
|
||
// let some transforms arrive | ||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; | ||
|
||
let mut new_tfm = tf2_msgs::TFMessage::default(); | ||
for old_tfs in &tfm.transforms { | ||
// TODO(lucasw) make a lookup_most_recent_transform and then don't need the None | ||
let res = | ||
listener.lookup_transform(&old_tfs.header.frame_id, &old_tfs.child_frame_id, None); | ||
match res { | ||
Ok(new_tfs) => { | ||
new_tfm.transforms.push(new_tfs); | ||
// TODO(lucasw) compare old values to current values, warn if large | ||
} | ||
Err(err) => { | ||
eprintln!("# {err:?} -> going to use old version for this transform"); | ||
new_tfm.transforms.push(old_tfs.clone()); | ||
} | ||
} | ||
} | ||
|
||
let toml = tf_util::transforms_to_toml(tfm)?; | ||
print!("\n\n{toml}"); | ||
|
||
Ok(()) | ||
} |
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