#[non_exhaustive]pub struct QueryFormat {Show 21 fields
pub mode: Resolution,
pub position: Resolution,
pub velocity: Resolution,
pub torque: Resolution,
pub q_current: Resolution,
pub d_current: Resolution,
pub abs_position: Resolution,
pub power: Resolution,
pub motor_temperature: Resolution,
pub trajectory_complete: Resolution,
pub home_state: Resolution,
pub voltage: Resolution,
pub temperature: Resolution,
pub fault: Resolution,
pub aux1_gpio: Resolution,
pub aux2_gpio: Resolution,
pub aux1_pwm_input_period_us: Resolution,
pub aux1_pwm_input_duty_cycle: Resolution,
pub aux2_pwm_input_period_us: Resolution,
pub aux2_pwm_input_duty_cycle: Resolution,
pub extra: [(u16, Resolution); 16],
}Expand description
Format configuration for queries.
Specifies which registers to query and at what resolution.
Setting a field to Resolution::Ignore means that register will not be queried.
§Examples
use moteus_protocol::Resolution;
use moteus_protocol::query::QueryFormat;
// Default format queries position, velocity, torque, and q_current
let default = QueryFormat::default();
// Comprehensive format includes all standard registers
let full = QueryFormat::comprehensive();
// Or customize individual registers
let mut custom = QueryFormat::default();
custom.abs_position = Resolution::Float;
custom.voltage = Resolution::Int16;Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.mode: Resolution§position: Resolution§velocity: Resolution§torque: Resolution§q_current: Resolution§d_current: Resolution§abs_position: Resolution§power: Resolution§motor_temperature: Resolution§trajectory_complete: Resolution§home_state: Resolution§voltage: Resolution§temperature: Resolution§fault: Resolution§aux1_gpio: Resolution§aux2_gpio: Resolution§aux1_pwm_input_period_us: Resolution§aux1_pwm_input_duty_cycle: Resolution§aux2_pwm_input_period_us: Resolution§aux2_pwm_input_duty_cycle: Resolution§extra: [(u16, Resolution); 16]Extra registers to query, as (register_number, resolution) pairs.
Entries with Resolution::Ignore are unused. Active entries must be
sorted by register number (maintained by add_extra).
Implementations§
Source§impl QueryFormat
impl QueryFormat
Sourcepub fn minimal() -> QueryFormat
pub fn minimal() -> QueryFormat
Creates a minimal query format (mode, position, velocity, torque only).
Sourcepub fn comprehensive() -> QueryFormat
pub fn comprehensive() -> QueryFormat
Creates a comprehensive query format with all common fields.
Sourcepub fn extra_count(&self) -> usize
pub fn extra_count(&self) -> usize
Returns the number of active extra register entries.
Sourcepub fn add_extra(&mut self, register: u16, resolution: Resolution)
pub fn add_extra(&mut self, register: u16, resolution: Resolution)
Adds an extra register to query.
Sourcepub fn serialize(&self, frame: &mut CanFdFrame) -> u8
pub fn serialize(&self, frame: &mut CanFdFrame) -> u8
Serializes the query to a CAN frame and returns expected reply size.
Examples found in repository?
examples/protocol_only.rs (line 64)
29fn main() {
30 println!("=== moteus-protocol Example ===\n");
31
32 // Example 1: Create a stop command
33 println!("1. Creating a stop command for servo ID 1:");
34 let mut stop_frame = CanFdFrame::new();
35 stop_frame.arbitration_id = calculate_arbitration_id(0, 1, 0, true);
36 StopCommand::serialize(&mut stop_frame);
37 print_frame(&stop_frame);
38
39 // Example 2: Create a position command using builder pattern
40 println!("\n2. Creating a position command:");
41 let mut pos_frame = CanFdFrame::new();
42 pos_frame.arbitration_id = calculate_arbitration_id(0, 1, 0, true);
43
44 let pos_cmd = PositionCommand::new()
45 .position(0.5) // 0.5 revolutions
46 .velocity(1.0) // 1.0 rev/s
47 .kp_scale(1.0)
48 .kd_scale(1.0);
49 let pos_format = PositionFormat::default();
50
51 pos_cmd.serialize(&mut pos_frame, &pos_format);
52 print_frame(&pos_frame);
53
54 // Example 3: Create a query-only command
55 println!("\n3. Creating a query-only command:");
56 let mut query_frame = CanFdFrame::new();
57 query_frame.arbitration_id = calculate_arbitration_id(0, 1, 0, true);
58
59 let mut custom_query = QueryFormat::default();
60 custom_query.position = Resolution::Float; // Request full precision
61 custom_query.velocity = Resolution::Float;
62 custom_query.torque = Resolution::Float;
63
64 let reply_size = custom_query.serialize(&mut query_frame);
65 print_frame(&query_frame);
66 println!(" Expected reply size: {} bytes", reply_size);
67
68 // Example 4: Parse a simulated response
69 println!("\n4. Parsing a simulated response:");
70
71 // Construct a fake response frame as if from servo ID 1
72 let mut response = CanFdFrame::new();
73 response.arbitration_id = calculate_arbitration_id(1, 0, 0, false);
74
75 // Manually construct response data:
76 // This would normally come from the CAN bus
77 // Format: [reply header] [register] [values...]
78 response.data[0] = 0x21; // Reply Int8, count=1
79 response.data[1] = 0x00; // Register 0 (Mode)
80 response.data[2] = 0x0A; // Mode = Position (10)
81 response.data[3] = 0x2D; // Reply Float (0x2c), count=1 (0x01)
82 response.data[4] = 0x01; // Register 1 (Position)
83 response.data[5] = 0x00; // Position as f32 (0.5)
84 response.data[6] = 0x00;
85 response.data[7] = 0x00;
86 response.data[8] = 0x3F;
87 response.size = 9;
88
89 let result = QueryResult::parse(&response);
90 println!(" Parsed QueryResult:");
91 println!(" Mode: {:?}", result.mode);
92 println!(" Position: {:.4} rev", result.position);
93 println!(" Velocity: {:.4} rev/s", result.velocity);
94 println!(" Torque: {:.4} Nm", result.torque);
95
96 // Example 5: Create a current (torque) command using builder pattern
97 println!("\n5. Creating a current command:");
98 let mut current_frame = CanFdFrame::new();
99 current_frame.arbitration_id = calculate_arbitration_id(0, 1, 0, true);
100
101 let current_cmd = CurrentCommand::new().d_current(0.0).q_current(0.5);
102 current_cmd.serialize(&mut current_frame, &CurrentFormat::default());
103 print_frame(¤t_frame);
104
105 // Example 6: Create a brake command
106 println!("\n6. Creating a brake command:");
107 let mut brake_frame = CanFdFrame::new();
108 brake_frame.arbitration_id = calculate_arbitration_id(0, 1, 0, true);
109
110 BrakeCommand::serialize(&mut brake_frame);
111 print_frame(&brake_frame);
112 println!(" Mode byte: {} (Brake=15)", brake_frame.data[2]);
113
114 println!("\n=== Done ===");
115}Trait Implementations§
Source§impl Clone for QueryFormat
impl Clone for QueryFormat
Source§fn clone(&self) -> QueryFormat
fn clone(&self) -> QueryFormat
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for QueryFormat
impl Debug for QueryFormat
Source§impl Default for QueryFormat
impl Default for QueryFormat
Source§fn default() -> QueryFormat
fn default() -> QueryFormat
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for QueryFormat
impl RefUnwindSafe for QueryFormat
impl Send for QueryFormat
impl Sync for QueryFormat
impl Unpin for QueryFormat
impl UnsafeUnpin for QueryFormat
impl UnwindSafe for QueryFormat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CommandExt for T
impl<T> CommandExt for T
Source§fn with_query(self, format: QueryFormat) -> WithQuery<Self>
fn with_query(self, format: QueryFormat) -> WithQuery<Self>
Attaches a query format override to this command.