Alyson Castiblanco
/
PARQUEADERO_VERTICAL
Codigo donde falta la comunicacion serial
mover.cpp@1:526bdd5faa37, 2018-09-04 (annotated)
- Committer:
- fabeltranm
- Date:
- Tue Sep 04 02:15:49 2018 +0000
- Revision:
- 1:526bdd5faa37
- Parent:
- draw.cpp@0:89b318e49395
entrega 1 sin comprobar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:89b318e49395 | 1 | |
fabeltranm | 1:526bdd5faa37 | 2 | #include "mover.h" |
fabeltranm | 0:89b318e49395 | 3 | #include "mbed.h" |
fabeltranm | 0:89b318e49395 | 4 | #include "math.h" |
fabeltranm | 0:89b318e49395 | 5 | |
fabeltranm | 0:89b318e49395 | 6 | |
fabeltranm | 1:526bdd5faa37 | 7 | PwmOut myServo1(PB_3); |
fabeltranm | 1:526bdd5faa37 | 8 | PwmOut myServo2(PB_4); |
fabeltranm | 1:526bdd5faa37 | 9 | PwmOut myServo3(PB_5); |
fabeltranm | 0:89b318e49395 | 10 | |
fabeltranm | 1:526bdd5faa37 | 11 | |
fabeltranm | 0:89b318e49395 | 12 | uint8_t ss_time=50; // tiempo de espera para moverse 1 mm en microsegundos |
fabeltranm | 0:89b318e49395 | 13 | |
fabeltranm | 0:89b318e49395 | 14 | void put_sstime(uint8_t vtime){ |
fabeltranm | 0:89b318e49395 | 15 | ss_time=vtime; |
fabeltranm | 0:89b318e49395 | 16 | |
fabeltranm | 0:89b318e49395 | 17 | } |
fabeltranm | 0:89b318e49395 | 18 | |
fabeltranm | 0:89b318e49395 | 19 | int coord2us(float coord) |
fabeltranm | 0:89b318e49395 | 20 | { |
fabeltranm | 0:89b318e49395 | 21 | if(0 <= coord <= MAXPOS) |
fabeltranm | 0:89b318e49395 | 22 | return int(750+coord*1900/50);// u6 |
fabeltranm | 0:89b318e49395 | 23 | return 750; |
fabeltranm | 0:89b318e49395 | 24 | |
fabeltranm | 0:89b318e49395 | 25 | } |
fabeltranm | 0:89b318e49395 | 26 | |
fabeltranm | 1:526bdd5faa37 | 27 | |
fabeltranm | 0:89b318e49395 | 28 | |
fabeltranm | 0:89b318e49395 | 29 | |
fabeltranm | 0:89b318e49395 | 30 | |
fabeltranm | 1:526bdd5faa37 | 31 | void mover_ser(uint8_t motor, uint8_t pos){ |
fabeltranm | 0:89b318e49395 | 32 | |
fabeltranm | 1:526bdd5faa37 | 33 | int pulseX = coord2us(pos); |
fabeltranm | 0:89b318e49395 | 34 | |
fabeltranm | 1:526bdd5faa37 | 35 | myServo1.pulsewidth_us(pulseX); |
fabeltranm | 1:526bdd5faa37 | 36 | |
fabeltranm | 0:89b318e49395 | 37 | |
fabeltranm | 0:89b318e49395 | 38 | } |
fabeltranm | 0:89b318e49395 | 39 | |
fabeltranm | 0:89b318e49395 | 40 | void init_servo() |
fabeltranm | 0:89b318e49395 | 41 | { |
fabeltranm | 1:526bdd5faa37 | 42 | myServo1.period_ms(20); |
fabeltranm | 1:526bdd5faa37 | 43 | myServo2.period_ms(20); |
fabeltranm | 1:526bdd5faa37 | 44 | myServo3.period_ms(20); |
fabeltranm | 0:89b318e49395 | 45 | |
fabeltranm | 0:89b318e49395 | 46 | |
fabeltranm | 0:89b318e49395 | 47 | } |