11use eyre:: Result ;
22use robstride:: robstride03:: { RobStride03 , RobStride03Command } ;
33use robstride:: SocketCanTransport ;
4+ use robstride:: { Actuator , ControlCommand , Protocol , Transport , TxCommand , TypedCommandData } ;
5+ use std:: sync:: Arc ;
46use std:: time:: Duration ;
57use tokio:: sync:: mpsc;
6- use std:: sync:: Arc ;
7- use tracing:: { info, error, trace} ;
8- use robstride:: { TxCommand , Protocol , ControlCommand , Actuator , Transport , TypedCommandData } ;
8+ use tracing:: { error, info, trace} ;
99use tracing_subscriber:: { fmt, EnvFilter } ;
1010
1111#[ tokio:: main]
@@ -18,11 +18,11 @@ async fn main() -> Result<()> {
1818
1919 // Create channel for sending commands
2020 let ( tx, mut rx) = mpsc:: channel ( 32 ) ;
21-
21+
2222 // Initialize CAN transport
2323 let transport = SocketCanTransport :: new ( "can1" . to_string ( ) ) . await ?;
24- let mut transport_clone = transport. clone ( ) ; // Make this mutable
25-
24+ let mut transport_clone = transport. clone ( ) ; // Make this mutable
25+
2626 // Spawn transport handling task
2727 let _transport_task = tokio:: spawn ( async move {
2828 info ! ( "Starting transport handling task" ) ;
@@ -45,44 +45,45 @@ async fn main() -> Result<()> {
4545
4646 // Create motor instance (using ID 1 and host ID 0)
4747 let motor = RobStride03 :: new ( 33 , 0 , tx) ;
48-
48+
4949 // Enable the motor
5050 println ! ( "Enabling motor..." ) ;
5151 motor. enable ( ) . await ?;
5252 tokio:: time:: sleep ( Duration :: from_millis ( 500 ) ) . await ;
53-
53+
5454 // Set some reasonable limits
5555 println ! ( "Setting limits..." ) ;
56- motor. set_max_torque ( 20.0 ) . await ?; // 20 Nm max torque
57- motor. set_max_velocity ( 5.0 ) . await ?; // 5 rad/s max velocity
58-
56+ motor. set_max_torque ( 20.0 ) . await ?; // 20 Nm max torque
57+ motor. set_max_velocity ( 5.0 ) . await ?; // 5 rad/s max velocity
58+
5959 // Create a position command (1 radian)
6060 let target_position = 0.0 ;
6161 println ! ( "Moving to position: {} radians" , target_position) ;
6262
6363 let command = RobStride03Command {
6464 target_angle_rad : target_position,
6565 target_velocity_rads : 0.0 ,
66- kp : 25.0 , // Position gain
67- kd : 5.0 , // Velocity gain
66+ kp : 25.0 , // Position gain
67+ kd : 5.0 , // Velocity gain
6868 torque_nm : 0.0 ,
69- } . to_control_command ( ) ;
70-
69+ }
70+ . to_control_command ( ) ;
71+
7172 // Send the command
7273 motor. control ( command) . await ?;
73-
74+
7475 // Wait for movement
7576 tokio:: time:: sleep ( Duration :: from_secs ( 2 ) ) . await ;
76-
77+
7778 // Get feedback (position)
7879 motor. get_feedback ( ) . await ?;
79-
80+
8081 // Disable the motor
8182 println ! ( "Disabling motor..." ) ;
8283 motor. disable ( false ) . await ?;
83-
84+
8485 // Wait a moment before shutting down
8586 tokio:: time:: sleep ( Duration :: from_millis ( 100 ) ) . await ;
86-
87+
8788 Ok ( ( ) )
8889}
0 commit comments