Silvie van den Bogaard
/
determine_x_setpoint
Determines the setpoint in x direction of the robot. Robot specific variables still have to be set.
main.cpp@0:0d70149fdb98, 2018-10-08 (annotated)
- Committer:
- Duif
- Date:
- Mon Oct 08 15:27:21 2018 +0000
- Revision:
- 0:0d70149fdb98
- Child:
- 1:f120a8734106
read the value of the button;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Duif | 0:0d70149fdb98 | 1 | //Determining the setpoint that the thing will have to follow |
Duif | 0:0d70149fdb98 | 2 | #include "mbed.h" |
Duif | 0:0d70149fdb98 | 3 | #include "MODSERIAL.h" |
Duif | 0:0d70149fdb98 | 4 | DigitalIn button(SW2); |
Duif | 0:0d70149fdb98 | 5 | DigitalIn direction(SW3); |
Duif | 0:0d70149fdb98 | 6 | MODSERIAL pc(USBTX, USBRX); //makes sure the computer is hooked up |
Duif | 0:0d70149fdb98 | 7 | |
Duif | 0:0d70149fdb98 | 8 | //defining of the variables |
Duif | 0:0d70149fdb98 | 9 | float x_prev = 0; //previous setpoint |
Duif | 0:0d70149fdb98 | 10 | float x_new; //new setpoint |
Duif | 0:0d70149fdb98 | 11 | float x_max; //maximum value of setpoint |
Duif | 0:0d70149fdb98 | 12 | float x_min; //minimum value of setpoint |
Duif | 0:0d70149fdb98 | 13 | float v; //moving speed of setpoint |
Duif | 0:0d70149fdb98 | 14 | volatile int s; //value of the switch |
Duif | 0:0d70149fdb98 | 15 | |
Duif | 0:0d70149fdb98 | 16 | //equation is x_new = x_prev + s*v*dt |
Duif | 0:0d70149fdb98 | 17 | |
Duif | 0:0d70149fdb98 | 18 | void EMGOn(){ |
Duif | 0:0d70149fdb98 | 19 | x_new = x_prev + s*v; |
Duif | 0:0d70149fdb98 | 20 | x_prev = x_new; |
Duif | 0:0d70149fdb98 | 21 | pc.printf("Set: %f",x_new); |
Duif | 0:0d70149fdb98 | 22 | } |
Duif | 0:0d70149fdb98 | 23 | |
Duif | 0:0d70149fdb98 | 24 | int main() |
Duif | 0:0d70149fdb98 | 25 | { |
Duif | 0:0d70149fdb98 | 26 | pc.baud(115200); |
Duif | 0:0d70149fdb98 | 27 | |
Duif | 0:0d70149fdb98 | 28 | while (true) { |
Duif | 0:0d70149fdb98 | 29 | s = button.read(); |
Duif | 0:0d70149fdb98 | 30 | } |
Duif | 0:0d70149fdb98 | 31 | } |