-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdio.h> | ||
#include "sim.c" | ||
|
||
void main(){ | ||
float rk[] = {0.75, 0.5, 1}; | ||
float vk = 0.0; | ||
float uk = 0.0; | ||
|
||
int x, z; | ||
int y = 0; | ||
|
||
for ( z=0 ; z<3 ; z++ ) { | ||
for ( x=0 ; x<250 ; x++ ) { | ||
if ( y == 0 ) { | ||
uk = Controller(rk[z] - vk); | ||
} | ||
vk = Motor(uk); | ||
printf("%f %f %f\n", rk[z], uk, vk); | ||
y = y>8 ? 0 : ++y; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* File: motorsim.c | ||
* Author: Koldo Basterretxea | ||
* | ||
* Created on 15 de abril de 2020, 12:51 | ||
*/ | ||
|
||
// Motor | ||
|
||
const float c[] = {0.35003, 0.062554}; | ||
const float d[] = {-0.84659, 0.00183}; | ||
|
||
float v[] = {0, 0}; | ||
float th[] = {0, 0}; | ||
|
||
volatile float Motor(float vk) { | ||
float thk = (c[0]*v[0]) + (c[1]*v[1]) - (d[0]*th[0]) - (d[1]*th[1]); // abiadura ardatzean rad/sec | ||
|
||
v[1]=v[0]; | ||
v[0]=vk; | ||
th[1]=th[0]; | ||
th[0]=thk; | ||
|
||
return thk*9.549297; // rad/sec to rpm | ||
} | ||
|
||
// Controller | ||
|
||
const float b[] = {0.005455, 0.003455}; | ||
const float a = -1; | ||
|
||
volatile float uk = 0; | ||
float uk1 = 0; | ||
float ek1 = 0;; | ||
|
||
volatile float Controller(float ek) { | ||
uk = (b[0]*ek) + (b[1]*ek1) - (a*uk); | ||
if (uk > 6) { | ||
uk=6; | ||
} | ||
|
||
uk1=uk; | ||
ek1=ek; | ||
|
||
return uk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters