tune_gains_sim.cpp
Go to the documentation of this file.
00001 #include "simulator.h"
00002 
00003 double get_wall_clock_time()
00004 {
00005     timeval tim;
00006     gettimeofday(&tim, NULL);
00007     double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
00008     return t1;
00009 }
00010 
00011 
00012 int main(int argc, char **argv)
00013 {
00014     ros::init(argc, argv, "sim_arm");
00015     ros::NodeHandle n;
00016 
00017     tf::TransformBroadcaster br;                                                
00018     tf::Transform tf_transform;
00019 
00020     Simulator simulator(n);
00021     ros::Subscriber sub1 = n.subscribe("/sim_arm/command/jep", 100, &Simulator::JepCallback, &simulator);
00022     ros::Subscriber sub2 = n.subscribe("/sim_arm/command/joint_impedance", 100, &Simulator::ImpedanceCallback, &simulator);
00023     //ros::Publisher data_pub = nh_.advertise<hrl_msgs::FloatArrayBare>("/sim_arm/tune_gains/data", 100);
00024 
00025 
00026     int torque_step(0);
00027     int q_pub_step(0);
00028     int skin_step(0);
00029     int clock_pub_step(0);
00030 
00031     ROS_INFO("Before most things \n");
00032 
00033     int resol;
00034     //    float resolution;
00035     while (n.getParam("/m3/software_testbed/resolution", resol) == false)
00036     {
00037         sleep(0.1);
00038     }
00039     double resolution = (double) resol;
00040 
00041     ROS_INFO("After getting first parameter \n");
00042 
00043     dInitODE();
00044     // setup pointers to drawstuff callback functions
00045 
00046     simulator.world.setGravity(0, 0, 0);
00047 
00048     ROS_INFO("Before create_robot \n");
00049 
00050     // make robot and go to starting configuration.
00051     simulator.create_robot();
00052     //ROS_INFO("Before going to initial position \n");
00053     //simulator.go_initial_position(); // initial jep defined inside this function.
00054     //ROS_INFO("After going to initial position \n");
00055 
00056     // add obstacles.
00057 
00058     ROS_INFO("Starting Simulation now ... \n");
00059 
00060     double t_now = get_wall_clock_time() - simulator.timestep;
00061     double t_expected;
00062 
00063     while (ros::ok())
00064     {
00065       //simulator.space.collide(&simulator, &simulator.nearCallback);
00066 
00067         //simulation will not run faster than real-time.
00068         t_expected = t_now + simulator.timestep;
00069         t_now = get_wall_clock_time();
00070         if (t_now < t_expected)
00071             usleep(int((t_expected - t_now)*1000000. + 0.5));
00072 
00073         simulator.world.step(simulator.timestep);
00074 
00075         simulator.cur_time += simulator.timestep;
00076         rosgraph_msgs::Clock c;
00077         c.clock.sec = int(simulator.cur_time);
00078         c.clock.nsec = int(1000000000*(simulator.cur_time-int(simulator.cur_time)));
00079 
00080         //simulator.sense_forces();
00081 
00082         clock_pub_step++;
00083         torque_step++;
00084         q_pub_step++;
00085         skin_step++;
00086 
00087         if (clock_pub_step >= 0.002/simulator.timestep)
00088         {
00089             simulator.clock_pub.publish(c);
00090             clock_pub_step = 0;
00091         }
00092 
00093         simulator.get_joint_data();
00094         if (q_pub_step >= 0.01/simulator.timestep)
00095         {
00096             simulator.publish_angle_data();
00097             q_pub_step = 0;
00098 
00099             tf_transform.setOrigin(tf::Vector3(0., 0., 0.0));
00100             tf_transform.setRotation(tf::Quaternion(0., 0., 0.));
00101 
00102             br.sendTransform(tf::StampedTransform(tf_transform,
00103                         ros::Time::now(), "/world",
00104                         "/torso_lift_link"));
00105         }
00106 
00107         //simulator.update_friction_and_obstacles();
00108 
00109         if (skin_step >= 0.01/simulator.timestep)
00110         {
00111             simulator.update_linkage_viz();
00112             simulator.update_taxel_simulation(resolution);
00113             simulator.publish_imped_skin_viz();
00114             skin_step = 0;
00115         }
00116 
00117         if (torque_step >= 0.001/simulator.timestep)
00118         {
00119             simulator.calc_torques();
00120             torque_step = 0;
00121         }
00122 
00123         simulator.set_torques();
00124         simulator.clear();
00125 
00126         ros::spinOnce();
00127     }
00128 
00129     dCloseODE();
00130 }
00131 
00132 


hrl_software_simulation_darpa_m3
Author(s): Marc Killpack and Advait Jain. Advisor: Prof. Charlie Kemp. Healthcare Robotics Lab, Georgia Tech
autogenerated on Wed Nov 27 2013 11:35:07