Expand description
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
Comamnd
is anInstruction
with a module address. - NonValid
Error Code - The result of attempting to converted a number that is not a valid status code into
Status
. - Reply
- A TMCM module will respond with a
Reply
after receiving aCommand
.
Enums§
- ErrStatus
- A
Status
that indicate anError
has occured. - Error
- All possible errors when communicating with
- OkStatus
- A
Status
that indicates that everything went well. - Status
- Every reply from a
Module
contains aStatus
Traits§
- Axis
Parameter - Axis parameter - useable with SAP, GAP, AAP, STAP and/or RSAP instructions.
- Instruction
- A
TMCL
Instruction
- Interface
- A interface for a TMCM module
- Readable
Axis Parameter - An axis parameter useable with the GAP instruction.
- Writeable
Axis Parameter - An axis parameter useable with the SAP instruction.