simulator.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 int main(int argc, char **argv)
00012 {
00013     ros::init(argc, argv, "sim_arm");
00014     ros::NodeHandle n;
00015     Simulator simulator(n);
00016     ros::Subscriber sub1 = n.subscribe("/sim_arm/command/jep", 100, &Simulator::JepCallback, &simulator);
00017     ros::Subscriber sub2 = n.subscribe("/sim_arm/command/joint_impedance", 100, &Simulator::ImpedanceCallback, &simulator);
00018     tf::TransformBroadcaster br;                                                
00019     tf::Transform tf_transform;
00020     int torque_step(0);
00021     int q_pub_step(0);
00022     int skin_step(0);
00023     int clock_pub_step(0);
00024 
00025 
00026     ROS_INFO("Before most things \n");
00027 
00028     ROS_INFO("After getting first parameter \n");
00029 
00030     dInitODE();
00031     // setup pointers to drawstuff callback functions
00032 
00033     simulator.world.setGravity(0, 0, 0);
00034 
00035     ROS_INFO("Before create_robot \n");
00036 
00037     // make robot and go to starting configuration.
00038     simulator.create_robot();
00039     ROS_INFO("Before going to initial position \n");
00040     simulator.go_initial_position(); // initial jep defined inside this function.
00041     ROS_INFO("After going to initial position \n");
00042 
00043     // add obstacles.
00044     simulator.create_movable_obstacles(); //call this first for stupid ROS param server sync.
00045     simulator.create_compliant_obstacles(); 
00046     simulator.create_fixed_obstacles();
00047     ROS_INFO("Starting Simulation now ... \n");
00048 
00049     double t_now = get_wall_clock_time() - simulator.timestep;
00050     double t_expected;
00051 
00052     while (ros::ok())
00053     {
00054         simulator.space.collide(&simulator, &simulator.nearCallback);
00055 
00056         // simulation will not run faster than real-time. - advait 2011
00057         /* this section may no longer be necessary though because
00058            we are no synchronizing the mpc controller and simulation 
00059            at least in some branches of the git code. - marc Sept 2012 */
00060         t_expected = t_now + simulator.timestep;
00061         t_now = get_wall_clock_time();
00062         if (t_now < t_expected)
00063             usleep(int((t_expected - t_now)*1000000. + 0.5));
00064 
00065         simulator.world.step(simulator.timestep);
00066 
00067         simulator.cur_time += simulator.timestep;
00068         rosgraph_msgs::Clock c;
00069         c.clock.sec = int(simulator.cur_time);
00070         c.clock.nsec = int(1000000000*(simulator.cur_time-int(simulator.cur_time)));
00071 
00072         simulator.sense_forces();
00073 
00074         clock_pub_step++;
00075         torque_step++;
00076         q_pub_step++;
00077         skin_step++;
00078 
00079         if (clock_pub_step >= 0.002/simulator.timestep)
00080         {
00081             simulator.clock_pub.publish(c);
00082             clock_pub_step = 0;
00083         }
00084 
00085         simulator.get_joint_data();
00086         if (q_pub_step >= 0.01/simulator.timestep)
00087         {
00088             simulator.publish_angle_data();
00089             q_pub_step = 0;
00090 
00091             tf_transform.setOrigin(tf::Vector3(0, 0, 0.0));
00092             tf_transform.setRotation(tf::Quaternion(0, 0, 0, 1.0));
00093 
00094             br.sendTransform(tf::StampedTransform(tf_transform,
00095                         ros::Time::now(), "/world",
00096                         "/torso_lift_link"));
00097         }
00098 
00099         simulator.update_friction_and_obstacles();
00100 
00101         if (skin_step >= 0.01/simulator.timestep)
00102         {
00103             simulator.update_linkage_viz();
00104             simulator.update_taxel_simulation();
00105             simulator.update_proximity_simulation();
00106             simulator.publish_imped_skin_viz();
00107             skin_step = 0;
00108         }
00109 
00110         if (torque_step >= 0.001/simulator.timestep)
00111         {
00112             simulator.calc_torques();
00113             torque_step = 0;
00114         }
00115 
00116         simulator.set_torques();
00117         simulator.clear();
00118 
00119         ros::spinOnce();
00120     }
00121 
00122     dCloseODE();
00123 }
00124 
00125 


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