4 个版本
0.1.3 | 2023 年 7 月 24 日 |
---|---|
0.1.2 | 2023 年 7 月 24 日 |
0.1.1 | 2023 年 7 月 23 日 |
0.1.0 | 2023 年 7 月 23 日 |
8 in #发布者
16KB
316 行
通用机器人框架
示例节点
use std::sync::{Arc, Mutex};
use client_example::msg::example_message::Position2DMessage;
use generic_robot_framework::main_loop;
use generic_robot_framework::models::tnode::Node;
use generic_robot_framework::models::tpub::Publisher;
use generic_robot_framework::models::tsub::Subscriber;
fn main() {
let atomic_data = Some(Arc::new(Mutex::new(0)));
let node: Node = Node::new("my_topic".to_string(), 1000);
let subscriber: Subscriber<Position2DMessage, Arc<Mutex<u64>>> = Subscriber::new("my_new_topic".to_string(), test_handle, atomic_data.clone());
let publisher: Publisher<Position2DMessage> = Publisher::new("my_new_topic".to_string());
let message = Position2DMessage {
x: 1,
y: 2
};
publisher.publish(message.clone());
main_loop!(node, {
println!("{}", atomic_data.as_ref().unwrap().lock().unwrap());
node.sleep();
});
}
fn test_handle(message: Position2DMessage, atomic_data: Option<Arc<Mutex<u64>>>) {
println!("{}", message);
let arc = atomic_data.unwrap();
let mut data = arc.lock().unwrap();
*data = message.y
}
示例消息
extern crate generic_robot_framework;
use generic_robot_framework::register_message;
register_message!(Position2DMessage {
x: u64,
y: u64,
});
工作区架构
project_workspace: # GRF package typed "Workspace"
src:
packages:
example_adapter: # GRF package typed "Adapter"
...
example_resource: # GRF package typed "Resource"
...
example_package: # GRF package typed "Module"
src:
msg: # Folder containing messages structs
- example_message.rs
bin: # Folder containing nodes scripts
- example_node.rs
- Cargo.toml
- Cargo.lock
- Cargo.toml
- Cargo.lock
依赖项
~10–19MB
~269K SLoC