inovo_rs/
lib.rs

1//! [![Static Badge](https://img.shields.io/badge/crate-inovo_rs-red)](https://crates.io/crates/inovo-rs)
2//! [![docs.rs](https://img.shields.io/docsrs/inovo-rs)](https://docs.rs/inovo-rs/latest/inovo_rs/)
3//!
4//! # Inovo Robot API
5//!
6//! `inovo_rs` is a library with communication, command, and utility function and data structure for
7//! intergrating inovo robot arm for automation solution.
8//!
9//! ## Installation
10//! ```bash
11//! cargo add inovo-rs
12//! ```
13//!
14//! ## Example
15//! ```no_run
16//! use inovo_rs::geometry::*;
17//! use inovo_rs::iva::CustomCommand;
18//! use inovo_rs::logger::Logger;
19//! use inovo_rs::robot::*;
20//!
21//! fn main() -> Result<(), RobotError> {
22//!     // create a new default logger
23//!     let mut logger = Logger::default_target("Robot Example");
24//!
25//!     logger.info("Creating new robot.");
26//!
27//!     // create a new client to the robot
28//!     let mut bot = Robot::defaut_logger(50003, "192.168.1.121")?;
29//!
30//!     // Motion Parameter
31//!     //
32//!     // motion parameter for the robot's movement
33//!     let param_1 = MotionParam::new()
34//!         .set_speed(100.0)
35//!         .set_accel(100.0)
36//!         .set_blend_linear(1000.0)
37//!         .set_blend_angular(720.0)
38//!         .set_tcp_speed_linear(1000.0)
39//!         .set_tcp_speed_angular(720.0);
40//!     let param_2 = MotionParam::new()
41//!         .set_speed(10.0)
42//!         .set_accel(10.0)
43//!         .set_blend_linear(1.0)
44//!         .set_blend_angular(1.0)
45//!         .set_tcp_speed_linear(100.0)
46//!         .set_tcp_speed_angular(100.0);
47//!     let param_3 = MotionParam::new()
48//!         .set_speed(50.0)
49//!         .set_accel(50.0)
50//!         // you can leave some of the parameter unset
51//!         // the robot will just not change the value of when recieve command
52//!         // .set_blend_linear(1.0)
53//!         // .set_blend_angular(1.0)
54//!         .set_tcp_speed_linear(100.0)
55//!         .set_tcp_speed_angular(90.0);
56//!
57//!     // Getting Current Transform and Joint Coordinate of the robot
58//!     //
59//!     // get the current transform of the robot
60//!     let home_transform = bot.get_current_transform()?;
61//!     // get the current joint coordinate of the robot
62//!     let home_joint_coord = bot.get_current_joint()?;
63//!
64//!     // Handling geometry data
65//!     let vz = Transform::from_z(100.0);
66//!     let rz = Transform::from_z(10.0);
67//!     let vxyz = Transform::from_vector([100.0, 100.0, 100.0]);
68//!     let tx = home_transform.clone().then_x(100.0);
69//!     let ty = home_transform.clone().then_y(100.0);
70//!     let j1 = home_joint_coord.clone().then_j1(90.0);
71//!     let j2 = j1.clone() + JointCoord::from([10.0, 10.0, 10.0, 10.0, 10.0, 10.0]);
72//!
73//!     // Robot Command
74//!     //
75//!     // set the motion of the robot
76//!     bot.set_param(param_1.clone())?;
77//!     // perform a linear motion
78//!     bot.linear(tx.clone())?;
79//!     // sleep
80//!     bot.sleep(1.0)?;
81//!     // you can chain command
82//!     // it will execute on at a time
83//!     bot.linear_relative(vz.clone())?
84//!         .sleep(1.0)?
85//!         .set_param(param_2.clone())?
86//!         .joint(ty.clone())?
87//!         .sleep(1.0)?
88//!         .joint_relative(vxyz.clone())?
89//!         .sleep(1.0)?
90//!         // joint motion can take both `JointCoord` and `Transform` as target
91//!         // while other can only take `Transform` as target
92//!         .joint(j1.clone())?
93//!         .set_param(param_3.clone())?
94//!         .joint(home_transform.clone())?;
95//!
96//!     // you can also create a command sequence for all of the command
97//!     let command_sequence = CommandSequence::new()
98//!         .then_set_param(param_1.clone())
99//!         .then_linear(home_transform.clone())
100//!         .then_sleep(1.0)
101//!         .then_linear(tx.clone())
102//!         .then_linear_relative(vz.clone())
103//!         .then_set_param(param_2.clone())
104//!         .then_joint(ty.clone())
105//!         .then_joint_relative(vz.clone())
106//!         .then_set_param(param_3.clone())
107//!         .then_joint(j2.clone())
108//!         .then_joint(home_joint_coord.clone());
109//!     // in this case the robot will execute all of them before responing
110//!     bot.sequence(command_sequence.clone())?;
111//!
112//!     // Context
113//!     //
114//!     // the `with` keywork denote context manager
115//!     // it will create a RAII guard that reverse the motion automatically
116//!     // after the guard is drop
117//!     bot.with_linear(tx.clone())?;
118//!     {
119//!         let guard = bot.with_linear_relative(vz.clone())?;
120//!         // do some other stuff
121//!     } // the robot motion will automatically reverse here
122//!       //
123//!       // you can chain context like this
124//!     bot.with_linear_relative(Transform::from_x(100.0))?
125//!         .with_linear_relative(Transform::from_y(100.0))?
126//!         .with_linear_relative(Transform::from_z(100.0))?;
127//!     //
128//!     //
129//!     //
130//!     {
131//!         let mut guard_1 = bot.with_joint(ty.clone())?;
132//!         let mut guard_2 = guard_1.with_joint_relative(rz.clone())?;
133//!         let mut guard_3 = guard_2.with_joint(j1.clone())?;
134//!         // do some other stuff
135//!         //
136//!         // you can early drop the guard and its motion will be reverse
137//!         drop(guard_3)
138//!         //
139//!         // some other stuff
140//!         //
141//!     } // all guard will be reverse here
142//!       //
143//!       //
144//!       // you can even do it with a while sequence
145//!     bot.with_sequence(command_sequence)?;
146//!
147//!     // Gripper interface
148//!     //
149//!     // activating the gripper
150//!     bot.gripper_activate()?;
151//!     // getting/setting the gripper
152//!     bot.gripper_set("open")?;
153//!     logger.info(format!("gripper get: {}", bot.gripper_get()?));
154//!     bot.gripper_set("close")?;
155//!     logger.info(format!("gripper get: {}", bot.gripper_get()?));
156//!
157//!     // Digital IO
158//!     //
159//!     // getting/setting the digital IO
160//!     for i in 0..8 {
161//!         bot.beckhoff_set(i, true)?;
162//!         bot.sleep(1.0)?;
163//!
164//!         let b = bot.beckhoff_get(i)?;
165//!         logger.info(format!("Beckhoff Input - port {}, state : {}", i, b));
166//!         bot.sleep(1.0)?;
167//!
168//!         bot.beckhoff_set(i, false)?;
169//!         bot.sleep(0.5)?;
170//!     }
171//!
172//!     // Data
173//!     //
174//!     // getting the data from robot data storeage
175//!     let my_bool: bool = bot.get_data("my bool")?;
176//!     let my_i64: i64 = bot.get_data("my i64")?;
177//!     let my_f64: f64 = bot.get_data("my f64")?;
178//!     let my_string: String = bot.get_data("my string")?;
179//!     let my_joint_coord: JointCoord = bot.get_data("my joint_coord")?;
180//!     let my_transform: Transform = bot.get_data("my transform")?;
181//!     let my_waypoint_j: JointCoord = bot.get_data("my waypoint")?;
182//!     let my_waypoint_t: Transform = bot.get_data("my waypoint")?;
183//!     logger.info(format!("my bool        : {}", my_bool));
184//!     logger.info(format!("my i64         : {}", my_i64));
185//!     logger.info(format!("my f64         : {}", my_f64));
186//!     logger.info(format!("my string      : {}", my_string));
187//!     logger.info(format!("my joint coord : {:?}", my_joint_coord));
188//!     logger.info(format!("my transform   : {:?}", my_transform));
189//!     logger.info(format!("my way point j : {:?}", my_waypoint_j));
190//!     logger.info(format!("my way point t : {:?}", my_waypoint_t));
191//!
192//!     // Custom Command
193//!     //
194//!     // you need to implement the custom command in block first
195//!     // then you can use it in here
196//!     let custom_command = CustomCommand::new()
197//!         .add_float("my_float", 69.420)
198//!         .add_string("my_string", "this is a string key");
199//!
200//!     let response = bot.custom(custom_command)?;
201//!     logger.info(response);
202//!
203//!     Ok(())
204//! }
205//! ```
206pub mod context;
207pub mod geometry;
208pub mod iva;
209pub mod logger;
210pub mod robot;
211pub mod ros_bridge;
212pub mod socket;