6 releases
Uses old Rust 2015
0.1.0-beta0 | May 25, 2018 |
---|---|
0.1.0-alpha4 | May 21, 2018 |
#1151 in Hardware support
49KB
1K
SLoC
TMCL.rs
Trinamic Motion Control Language (TMCL) in Rust
License
Licensed under either of
-
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
-
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
TMCL - Trinamic Motion Control Language
As described in The TMCL Reference
Examples
Socketcan
To use this example the socketcan feature must be enabled.
And a socketcan interface named vcan0
must exist.
extern crate tmcl;
extern crate socketcan;
use std::cell::RefCell;
use tmcl::modules::tmcm::instructions::*;
use tmcl::modules::tmcm::axis_parameters::*;
use tmcl::modules::tmcm::TmcmModule as Module;
fn main() {
# std::process::Command::new("sudo ip link add dev vcan0 type vcan").output();
# std::process::Command::new("sudo ip link set up vcan0").output();
let interface = RefCell::new(socketcan::CANSocket::open("vcan0").unwrap());
let module1 = Module::new(&interface, 1);
let module2 = Module::new(&interface, 2);
module1.write_command(ROR::new(0, 250)).unwrap();
module2.write_command(ROL::new(0, 250)).unwrap();
}
Socketcan and threading
To use this example the socketcan feature must be enabled.
And a socketcan interface named vcan0
must exist.
extern crate tmcl;
extern crate socketcan;
use std::sync::Mutex;
use std::sync::Arc;
use tmcl::modules::tmcm::instructions::*;
use tmcl::modules::tmcm::axis_parameters::*;
use tmcl::modules::tmcm::TmcmModule as Module;
fn main() {
# std::process::Command::new("sudo ip link add dev vcan0 type vcan").output();
# std::process::Command::new("sudo ip link set up vcan0").output();
let interface = Arc::new(Mutex::new(socketcan::CANSocket::open("vcan0").unwrap()));
let module1 = Module::new(interface.clone(), 1);
let module2 = Module::new(interface, 2);
std::thread::spawn(move || {
module1.write_command(ROR::new(0, 250)).unwrap();
});
std::thread::spawn(move || {
module2.write_command(ROL::new(0, 250)).unwrap();
});
}
No-std
When using with no-std you can implement Interface
on the interface you intent to use.
# // TODO: change ignore to no_run once panic_implementation is stabilized
#![no_std]
extern crate tmcl;
use core::cell::RefCell;
use tmcl::Interface;
use tmcl::Reply;
use tmcl::Command;
use tmcl::Instruction;
use tmcl::modules::tmcm::instructions::*;
use tmcl::modules::tmcm::axis_parameters::*;
use tmcl::modules::tmcm::TmcmModule as Module;
# struct MyInterface();
# struct MyInterfaceError();
# impl MyInterface { fn new() -> Self {unimplemented!()} }
impl Interface for MyInterface {
type Error = MyInterfaceError;
fn transmit_command<T: Instruction>(&mut self, command: &Command<T>) -> Result<(), Self::Error> {
// Implement transmit_command for your interface
# unimplemented!()
}
fn receive_reply(&mut self) -> Result<Reply, Self::Error> {
// Implement receive_reply for your interface
# unimplemented!()
}
}
fn main() {
let interface = RefCell::new(MyInterface::new());
let module1 = Module::new(&interface, 1);
let module2 = Module::new(&interface, 2);
module1.write_command(ROR::new(0, 250)).unwrap();
module2.write_command(ROL::new(0, 250)).unwrap();
}
Dependencies
~6–370KB