summaryrefslogtreecommitdiffhomepage
path: root/digital/asserv/models/limit_current.m
diff options
context:
space:
mode:
authorNicolas Schodet2007-08-06 10:52:37 +0200
committerNicolas Schodet2007-08-06 10:52:37 +0200
commit597eb3821de45a02fe5820266dbc87069162211a (patch)
treee0545a692bc3772c674bd1324148355074de5b3e /digital/asserv/models/limit_current.m
parent22351b5b3dcec28ec052eb70010bef53a39ef670 (diff)
Added motor models.
Diffstat (limited to 'digital/asserv/models/limit_current.m')
-rw-r--r--digital/asserv/models/limit_current.m44
1 files changed, 44 insertions, 0 deletions
diff --git a/digital/asserv/models/limit_current.m b/digital/asserv/models/limit_current.m
new file mode 100644
index 00000000..e3d3d790
--- /dev/null
+++ b/digital/asserv/models/limit_current.m
@@ -0,0 +1,44 @@
+% Limit current.
+motor;
+
+%global to_file = 1;
+
+function u = onoff (t)
+ global sys;
+ if (t < 1)
+ u = sys.control.u;
+ else
+ u = 0;
+ end
+end
+
+function u = limit_current (t, x)
+ global sys;
+ u = onoff (t);
+ % Limit current by knowing the current speed and the motor terminal
+ % resistance.
+ umax = sys.control.current * sys.motor.R + x(2) / sys.motor.Kw;
+ umin = - sys.control.current * sys.motor.R + x(2) / sys.motor.Kw;
+ % Uncomment this if the maximum current can be overshooted when braking:
+ %umax = max ([umax, 0]);
+ %umin = min ([umin, 0]);
+ u = min ([u, umax]);
+ u = max ([u, umin]);
+end
+
+global sys;
+sys.motor = re40g;
+sys.gear = gear4x;
+sys.load = robot10w80;
+sys.load.J /= 2; % Two motors.
+sys.control.func = "limit_current";
+sys.control.current = 20;
+sys.control.u = sys.motor.u;
+
+plotterm ("limit");
+sys_plot (2);
+
+sys.control.func = "onoff";
+
+plotterm ("nolimit");
+sys_plot (2);