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: Add move joints #74

Merged
merged 5 commits 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Currently, the following voraus.core functionality is exposed to the ROS 2 ecosy
- Set tcp wrench for impedance control (via topic `impedance_control/set_wrench`)
- Set stiffness for impedance control (via topic `impedance_control/set_stiffness`)
- Enable/disable impedance control mode (via service `impedance_control/enable` or `impedance_control/disable`)
- Move joints (via service `move_joints`)

## Configuration

Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ fn main() -> Result<(), RclrsError> {
move |request_header, request| rsc.disable_impedance_control(request_header, request)
});

let ros_node_copy = Arc::clone(&ros_node);
let _move_joints =
ros_node_copy.create_service::<voraus_interfaces::srv::MoveJoints, _>("~/move_joints", {
let rsc = Arc::clone(&ros_services);
move |request_header, request| rsc.move_joints(request_header, request)
});

let opc_ua_client_copy = Arc::clone(&opc_ua_client);
let _wrench_subscriber: Arc<Subscription<Wrench>> = ros_node.create_subscription(
"~/impedance_control/set_wrench",
Expand Down
30 changes: 30 additions & 0 deletions src/ros_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex};
use log::info;
use opcua::types::{NodeId, Variant};
use std_srvs::srv::{Empty_Request, Empty_Response};
use voraus_interfaces::srv::{MoveJoints_Request, MoveJoints_Response};

use crate::opc_ua_client::OPCUAClient;

Expand Down Expand Up @@ -47,4 +48,33 @@ impl ROSServices {
structure_needs_at_least_one_member: 0,
}
}

pub fn move_joints(
&self,
_request_header: &rclrs::rmw_request_id_t,
request: MoveJoints_Request,
) -> MoveJoints_Response {
info!("ROS service call: Move Joints");
let object_id = NodeId::new(1, 100210);
let method_id = NodeId::new(1, 100211);
self.opc_ua_client.lock().unwrap().call_method(
object_id,
method_id,
Some(vec![
request.relative.into(),
request.target_reference_cs.into(),
request.target_coordinate.into(),
request.arriving_cs.into(),
request.velocity_scaling.into(),
request.with_blending.into(),
request.blending_parameter.into(),
request.config_vector.into(),
request.command_id.into(),
request.manual_mode.into(),
]),
);
MoveJoints_Response {
structure_needs_at_least_one_member: 0,
}
}
}
31 changes: 30 additions & 1 deletion tests/helpers/opc_ua_test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use opcua::server::prelude::{
};
use opcua::server::session::SessionManager;
use opcua::sync::RwLock;
use opcua::types::{CallMethodRequest, CallMethodResult, ObjectId, StatusCode, Variant};
use opcua::types::{
Array, CallMethodRequest, CallMethodResult, ObjectId, StatusCode, Variant, VariantTypeId,
};
use std::path::PathBuf;
use std::sync::mpsc::Sender;
use std::sync::Arc;
Expand Down Expand Up @@ -102,6 +104,33 @@ fn add_methods(server: &mut Server, namespace: u16, assertion_tx: Sender<String>
"impedance_control/disable".to_string(),
assertion_tx.clone(),
);
add_method_stub(
server,
NodeId::new(namespace, 100210),
NodeId::new(namespace, 100211),
Some(vec![
Variant::Boolean(false),
Variant::UInt32(0),
// The opcua crate creates an array with dimension = Some([]) when decoding an empty array.
// The default trait used in the ros service caller generates an empty vector so this is the workaround
// to still have a useful assertion.
Array::new_multi(VariantTypeId::Double, Vec::new(), Vec::new())
.unwrap()
.into(),
Variant::UInt32(0),
Variant::Double(0.0),
Variant::Boolean(false),
Variant::Double(0.0),
Array::new_multi(VariantTypeId::Int32, Vec::new(), Vec::new())
.unwrap()
.into(),
Variant::UInt32(0),
Variant::Boolean(false),
]),
None,
"move_joints".to_string(),
assertion_tx.clone(),
);
}

/// Creates an OPC UA variable that is monotonously increasing.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_bridge_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
use common::{wait_for_function_to_pass, ManagedRosBridge};
use helpers::opc_ua_test_server::OPCUATestServer;
use std_srvs::srv::Empty;
use voraus_interfaces::srv::MoveJoints;

pub mod common;
pub mod helpers;
Expand Down Expand Up @@ -63,3 +64,4 @@ make_testcase_method!(
Empty,
test_disable_impedance_control
);
make_testcase_method!("move_joints", MoveJoints, test_move_joints);
1 change: 1 addition & 0 deletions voraus_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(msg_files
)

set(srv_files
"srv/MoveJoints.srv"
"srv/Voraus.srv"
)

Expand Down
11 changes: 11 additions & 0 deletions voraus_interfaces/srv/MoveJoints.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bool relative
uint32 target_reference_cs
float64[] target_coordinate
uint32 arriving_cs
float64 velocity_scaling
bool with_blending
float64 blending_parameter
int32[] config_vector
uint32 command_id
bool manual_mode
---
Loading