Crate tmcl [−] [src]
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() { 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() { 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.
#![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; 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 } fn receive_reply(&mut self) -> Result<Reply, Self::Error> { // Implement receive_reply for your interface } } 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(); }
Modules
modules |
Implementation of functionality special for different hardware modules |
Structs
Command |
A |
NonValidErrorCode |
The result of attempting to converted a number that is not a valid status code into |
Reply |
A TMCM module will respond with a |
Enums
ErrStatus |
A |
Error |
All possible errors when communicating with |
OkStatus |
A |
Status |
Every reply from a |
Traits
AxisParameter |
Axis parameter - useable with SAP, GAP, AAP, STAP and/or RSAP instructions. |
Instruction |
A |
Interface |
A interface for a TMCM module |
ReadableAxisParameter |
An axis parameter useable with the GAP instruction. |
WriteableAxisParameter |
An axis parameter useable with the SAP instruction. |