Skip to content
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

feat!: Allow different OPC UA arg types #71

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ fn main() -> Result<(), RclrsError> {
NodeId::new(1, 100182),
NodeId::new(1, 100267),
Some(vec![
msg.force.x,
msg.force.y,
msg.force.z,
msg.torque.x,
msg.torque.y,
msg.torque.z,
msg.force.x.into(),
msg.force.y.into(),
msg.force.z.into(),
msg.torque.x.into(),
msg.torque.y.into(),
msg.torque.z.into(),
]),
);
},
Expand All @@ -88,12 +88,12 @@ fn main() -> Result<(), RclrsError> {
NodeId::new(1, 100182),
NodeId::new(1, 100265),
Some(vec![
msg.translation.x,
msg.translation.y,
msg.translation.z,
msg.rotation.x,
msg.rotation.y,
msg.rotation.z,
msg.translation.x.into(),
msg.translation.y.into(),
msg.translation.z.into(),
msg.rotation.x.into(),
msg.rotation.y.into(),
msg.rotation.z.into(),
]),
);
},
Expand Down
12 changes: 6 additions & 6 deletions src/opc_ua_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ impl OPCUAClient {
Ok(())
}

pub fn call_method<T>(&self, object_id: NodeId, method_id: NodeId, args: Option<Vec<T>>)
where
T: Into<Variant>,
{
pub fn call_method(
&self,
object_id: NodeId,
method_id: NodeId,
arguments: Option<Vec<Variant>>,
) {
let cloned_session_lock = self.session.clone().unwrap();
let session = cloned_session_lock.read();
let arguments: Option<Vec<Variant>> =
args.map(|vec| vec.into_iter().map(Into::into).collect());
let method = CallMethodRequest {
object_id,
method_id,
Expand Down
6 changes: 3 additions & 3 deletions src/ros_services.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};

use log::info;
use opcua::types::NodeId;
use opcua::types::{NodeId, Variant};
use std_srvs::srv::{Empty_Request, Empty_Response};

use crate::opc_ua_client::OPCUAClient;
Expand All @@ -26,7 +26,7 @@ impl ROSServices {
self.opc_ua_client
.lock()
.unwrap()
.call_method(object_id, method_id, None::<Vec<()>>);
.call_method(object_id, method_id, None::<Vec<Variant>>);
Empty_Response {
structure_needs_at_least_one_member: 0,
}
Expand All @@ -42,7 +42,7 @@ impl ROSServices {
self.opc_ua_client
.lock()
.unwrap()
.call_method(object_id, method_id, None::<Vec<()>>);
.call_method(object_id, method_id, None::<Vec<Variant>>);
Empty_Response {
structure_needs_at_least_one_member: 0,
}
Expand Down
Loading