ROBOOP, A Robotics Object Oriented Package in C++
demo_2dof_pd.cpp
Go to the documentation of this file.
1 /*
2 ROBOOP -- A robotics object oriented package in C++
3 Copyright (C) 2002-2004 Etienne Lachance
4 
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 
19 
20 Report problems and direct all questions to:
21 
22 email: etienne.lachance@polymtl.ca or richard.gourdeau@polymtl.ca
23 
24 -------------------------------------------------------------------------------
25 Revision_history:
26 
27 2004/07/01: Etienne Lachance
28  -Added support for newmat's use_namespace #define, using ROBOOP namespace
29 */
40 #include "gnugraph.h"
41 #include "controller.h"
42 #include "control_select.h"
43 #include "dynamics_sim.h"
44 #include "robot.h"
45 #include "trajectory.h"
46 
47 #ifdef use_namespace
48 using namespace ROBOOP;
49 #endif
50 
60 class New_dynamics: public Dynamics
61 {
62 public:
63  New_dynamics(Robot_basic *robot_);
64  virtual void plot();
65 
68  RowVector tout;
69  Matrix xout;
70  int i;
71 };
72 
78 {
79  robot = robot_;
80  first_pass_plot = true;
81  i = 1;
82 }
83 
92 {
93  if(first_pass_plot)
94  {
95  xout = Matrix(x.Nrows(),(int)(nsteps*(tf_cont-to)+1)*x.Ncols());
96  xout.SubMatrix(1,x.Nrows(),1,x.Ncols()) = x;
97  tout = RowVector((int)(nsteps*(tf_cont-to)+1));
98  tout(1) = to;
99  i = 0;
100  first_pass_plot = false;
101  }
102 
103  if(robot)
104  {
105  tout(i+1) = time;
106  xout.SubMatrix(1,x.Nrows(),i*x.Ncols()+1,(i+1)*x.Ncols()) = x;
107  i++;
108  }
109 }
110 
111 
112 int main()
113 {
114 
115  Robot robot("conf/rr_dh.conf", "rr_dh");
116 
117  Trajectory_Select path("conf/q_2dof.dat");
118  Control_Select control("conf/pd_2dof.conf");
119 
120  New_dynamics dynamics(&robot);
121 
122  dynamics.set_controller(control);
123  dynamics.set_trajectory(path);
124  dynamics.set_time_frame(500);
125 
126  dynamics.Runge_Kutta4();
127 
128  set_plot2d("Robot joints position", "time (sec)", "q(i) (rad)", "q", DATAPOINTS,
129  dynamics.tout, dynamics.xout, 1, 2);
130 
131  return(0);
132 }
133 
134