-
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.
feat: Implement an examplary 6 axis robot
which provides its current measure positions as array in ns=1;100111.
- Loading branch information
1 parent
89f3bbb
commit 4ad68d7
Showing
2 changed files
with
82 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,78 @@ | ||
use opcua::server::prelude::{Config, DateTime, NodeId, Server, ServerConfig, Variable}; | ||
use std::f64::consts::PI; | ||
use std::path::PathBuf; | ||
use std::time::SystemTime; | ||
use std::time::UNIX_EPOCH; | ||
|
||
fn main() { | ||
sine_joint_positions(); | ||
} | ||
|
||
fn sine_joint_positions() { | ||
opcua::console_logging::init(); | ||
|
||
let mut server = | ||
Server::new(ServerConfig::load(&PathBuf::from("tests/resources/clock.conf")).unwrap()); | ||
|
||
add_timed_variable_array(&mut server); | ||
|
||
server.run(); | ||
} | ||
|
||
fn add_timed_variable_array(server: &mut Server) { | ||
// These will be the node id of the variable AxesMeasuredPosition | ||
let axes_measured_position = NodeId::new(1, "100111"); | ||
|
||
let address_space = server.address_space(); | ||
|
||
// The address space is guarded so obtain a lock to change it | ||
{ | ||
let mut address_space = address_space.write(); | ||
|
||
let axes_folder_id = address_space | ||
.add_folder("Axes", "Axes", &NodeId::objects_folder_id()) | ||
.unwrap(); | ||
|
||
let _ = address_space.add_variables( | ||
vec![Variable::new( | ||
&axes_measured_position, | ||
"AxesMeasuredPosition", | ||
"AxesMeasuredPosition", | ||
vec![0.0f64; 6], | ||
)], | ||
&axes_folder_id, | ||
); | ||
} | ||
|
||
{ | ||
let omegas: [f64; 6] = [ | ||
2.0 * PI * 0.25, | ||
2.0 * PI * 0.5, | ||
2.0 * PI, | ||
2.0 * PI * 1.5, | ||
2.0 * PI * 2.0, | ||
2.0 * PI * 2.5, | ||
]; | ||
|
||
server.add_polling_action(10, move || { | ||
let mut address_space = address_space.write(); | ||
|
||
let timestamp_epoch = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); | ||
let seconds = | ||
timestamp_epoch.as_secs() as f64 + timestamp_epoch.subsec_nanos() as f64 * 1e-9; | ||
|
||
let sine_values: Vec<f64> = omegas | ||
.iter() | ||
.map(|&omega| (omega * seconds).sin()) | ||
.collect(); | ||
|
||
let now = DateTime::now(); | ||
let _ = address_space.set_variable_value( | ||
axes_measured_position.clone(), | ||
sine_values, | ||
&now, | ||
&now, | ||
); | ||
}); | ||
} | ||
} |