Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Encoder HIDScope MODSERIAL mbed
Fork of Cases_homepos_picontrol_EMG_2 by
Diff: main.cpp
- Revision:
- 6:1597888c9a56
- Parent:
- 5:b9d5d7311dac
- Child:
- 7:22126f285d69
--- a/main.cpp Thu Oct 22 13:11:55 2015 +0000
+++ b/main.cpp Thu Oct 22 13:53:03 2015 +0000
@@ -16,7 +16,9 @@
//AnalogIn EMG_legright (A3);
Ticker controller;
Ticker ticker_regelaar;
-Ticker EMG_Control;
+Ticker EMG_Filter;
+Ticker Scope;
+//Ticker Encoder_Scope;
//Timer Timer_Calibration;
Encoder motor1(D12,D13);
HIDScope scope(3);
@@ -32,7 +34,7 @@
#define SAMPLETIME_REGELAAR 0.005
//define states
-enum state {HOME, CALIBRATIE, MOVE_MOTOR, BACKTOHOMEPOSITION, STOP};
+enum state {HOME, MOVE_MOTOR, BACKTOHOMEPOSITION, STOP};
uint8_t state = HOME;
// Berekening van de output shaft resolution. Het aantal counts per 1 graden verandering
@@ -128,15 +130,7 @@
y9 = biquad (u8, flp1_v1, flp1_v2, flp1_a1, flp1_a2, flp1_b0* 0.010386, flp1_b1* 0.010386, flp1_b2* 0.010386);
u9 = y9;
final_filter1 = biquad(u9, flp2_v1, flp2_v2, flp2_a1, flp2_a2, flp2_b0*0.000109, flp2_b1*0.000109, flp2_b2*0.000109);
-
- scope.set (0, y8);
- // scope.set (1, y2);
- // scope.set (2, y4);
- // scope.set (3, y7);
- scope.set (1, final_filter1);
- //scope.set (2, final_filter1);
- scope.send ();
- }
+}
void motor1_controlPI()
@@ -159,12 +153,12 @@
void move_motor1_ccw (){
motor1_direction = 0;
- motor1_speed = 1;
+ motor1_speed = 0.4;
}
void move_motor1_cw (){
motor1_direction = 1;
- motor1_speed = 1;
+ motor1_speed = 0.4;
}
void movetohome(){
@@ -207,15 +201,25 @@
// wait(0.2f);
//}
-void print_position(){
- pc.printf("move motor \n\r");
- wait(0.2f);
+void HIDScope (){
+ scope.set (0, y8);
+ // scope.set (1, y2);
+ // scope.set (2, y4);
+ // scope.set (3, y7);
+ scope.set (1, final_filter1);
+ //scope.set (2, final_filter1);
+ scope.set(2, motor1.getPosition());
+ scope.send ();
}
+
+
+
int main()
{
while (true) {
pc.baud(9600); //pc baud rate van de computer
- EMG_Control.attach_us(Filters,1e3);
+ EMG_Filter.attach_us(Filters, 1e3);
+ Scope.attach_us(HIDScope, 1e3);
switch (state) { //zorgt voor het in goede volgorde uitvoeren van de cases
@@ -225,7 +229,7 @@
//read_encoder1();
gethome();
pc.printf("Home-position is %f\n\r", H);
- state = CALIBRATIE;
+ state = MOVE_MOTOR;
wait(5);
break;
}
@@ -255,7 +259,7 @@
pc.printf("move_motor\n\r");
while (state == MOVE_MOTOR){
move_motor1();
- print_position();
+ //print_position();
if (button_1 == pressed && button_2 == pressed){
state = BACKTOHOMEPOSITION;
}
