Tetrapod Project
torque_step_response_test.cpp
Go to the documentation of this file.
1 #include "ros/ros.h"
2 #include <ros/console.h>
3 
5 
6 int main(int argc, char **argv)
7 {
8  bool USE_POSITION_CONTROL = false;
9 
10  double PUBLISH_FREQUENCY = 100.0;
11 
12  double STEP_TIME = 0.2;
13 
14  double APPLY_TORQUE_DURATION = 1.0;
15 
16  double SETPOINT_TORQUE = 5.0;
17 
18  SingleMotorController controller(PUBLISH_FREQUENCY, USE_POSITION_CONTROL);
19 
20  controller.initROS();
21 
22  controller.initializeMotor();
23 
24  ros::Rate check_for_messages_rate(1);
25 
26  ros::Rate send_command_rate(PUBLISH_FREQUENCY);
27 
28  // Make sure we have received initial states from the motor
29  while(!controller.initialStateReceived())
30  {
31  controller.checkForNewMessages();
32  ROS_INFO("Waiting for state");
33  controller.printAll();
34  check_for_messages_rate.sleep();
35  }
36 
37  // Wait for the start signal
38  while(!controller.readyToProceed())
39  {
40  controller.checkForNewMessages();
41  ROS_INFO("Waiting for ready to proceed");
42  controller.printAll();
43  check_for_messages_rate.sleep();
44  }
45 
46  // Apply zero torque for a fixed duration and log the states
47  for(int i = 0; i < STEP_TIME*PUBLISH_FREQUENCY; i++)
48  {
49  controller.checkForNewMessages();
50  controller.setTorqueDirectly(0.0);
51  controller.writeToLog();
52  ROS_INFO("Start");
53  controller.printAll();
54  send_command_rate.sleep();
55  }
56 
57  // Apply the desired step torque for a fixed duration and log the states
58  for(int i = 0; i < APPLY_TORQUE_DURATION*PUBLISH_FREQUENCY; i++)
59  {
60  controller.checkForNewMessages();
61  controller.setTorqueDirectly(SETPOINT_TORQUE);
62  controller.writeToLog();
63  ROS_INFO("HIGH");
64  controller.printAll();
65  send_command_rate.sleep();
66  }
67 
68  // Apply zero torque until the program shuts down
69  while(true)
70  {
71  controller.checkForNewMessages();
72  controller.setTorqueDirectly(0.0);
73  ROS_INFO("FINISHED");
74  controller.printAll();
75  send_command_rate.sleep();
76  }
77 
78  return 0;
79 }
80 
void setTorqueDirectly(double _torque)
void initializeMotor(double _k_p_pos, double _k_d_pos, double _k_p_vel, double _k_i_vel, double _k_p_torque, double _k_i_torque)
int main(int argc, char **argv)