tes ir atas semua

Dependencies:   mbed ADS1115 StepperMotor SRF05 TPA81new

Committer:
Ezeuz
Date:
Fri Feb 02 15:46:42 2018 +0000
Revision:
4:9932af380e56
Parent:
1:ef90d942ce78
Child:
5:dae415fb4bad
Full functionality test for KRPAI ITB.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dmgongora 1:ef90d942ce78 1 /*****************************************************
dmgongora 1:ef90d942ce78 2 - Description: mbed to Dynamixel connection test using
dmgongora 1:ef90d942ce78 3 the library
dmgongora 1:ef90d942ce78 4 - Requirements:
dmgongora 1:ef90d942ce78 5 Dynamixel (i.e. DX116, RX28)
dmgongora 1:ef90d942ce78 6 MAX3088/MAX485 (RS485 transceiver)
dmgongora 1:ef90d942ce78 7 - Connections:
dmgongora 1:ef90d942ce78 8 MAX3088 -- mbed
dmgongora 1:ef90d942ce78 9 ======================
dmgongora 1:ef90d942ce78 10 Pin 1 -- Pin 14
dmgongora 1:ef90d942ce78 11 Pin 2 -- Pin 15
dmgongora 1:ef90d942ce78 12 Pin 4 -- Pin 13
dmgongora 1:ef90d942ce78 13
dmgongora 1:ef90d942ce78 14 - Comments:
dmgongora 1:ef90d942ce78 15 See schematic for wiring details and class
dmgongora 1:ef90d942ce78 16 documentation for available methods.
dmgongora 1:ef90d942ce78 17 *****************************************************/
Ezeuz 4:9932af380e56 18
dmgongora 0:79e2a8171b16 19 #include "mbed.h"
dmgongora 0:79e2a8171b16 20 #include "Dynamixel.h"
Ezeuz 4:9932af380e56 21 #include "TextLCD.h"
Ezeuz 4:9932af380e56 22 #include "Uvtron.h"
Ezeuz 4:9932af380e56 23
Ezeuz 4:9932af380e56 24 // Defines
Ezeuz 4:9932af380e56 25 #define IR_CONST 1.229
Ezeuz 4:9932af380e56 26
Ezeuz 4:9932af380e56 27 // Settings
Ezeuz 4:9932af380e56 28 Dynamixel* servos[3*6]; // Servo comm : tx, rx, txEn, id, baud
Ezeuz 4:9932af380e56 29 TextLCD lcd(PB_2, PB_1, PB_15, PB_14, PB_13, PC_4); // LCD : rs, e, d4-d7
Ezeuz 4:9932af380e56 30 AnalogIn ir(PA_5); // Sharp IR : analog
Ezeuz 4:9932af380e56 31 DigitalOut m2(PA_15); // extinguisher : 12V out M2
Ezeuz 4:9932af380e56 32 DigitalOut m1(PB_7); // extinguisher : 12V out M1, possibly broken
Ezeuz 4:9932af380e56 33 DigitalOut led1(PC_13); // GPIO high is 3V3
Ezeuz 4:9932af380e56 34 DigitalOut led2(PC_14);
Ezeuz 4:9932af380e56 35 DigitalIn sound(PA_6); // Sound act : digital
Ezeuz 4:9932af380e56 36
Ezeuz 4:9932af380e56 37 Uvtron uv(PA_11); // UVTron : interrupt
Ezeuz 4:9932af380e56 38
Ezeuz 4:9932af380e56 39 /* About interrupt
Ezeuz 4:9932af380e56 40 Where are the interrupt pins on NUCLEO-F411RE?
Ezeuz 4:9932af380e56 41
Ezeuz 4:9932af380e56 42 If you use a recent version of the mbed lib (right mouse button, update in the online compiler):
Ezeuz 4:9932af380e56 43 Every unique numbered pin. That means you can use any pin as InterruptIn, but you cannot use multiple
Ezeuz 4:9932af380e56 44 pins with the same number on a different port as InterruptIn. So you can use PA_1, PB_2, PA_3, PC_4, etc.
Ezeuz 4:9932af380e56 45 But in this example you could not use also PE_1. */
dmgongora 0:79e2a8171b16 46
dmgongora 0:79e2a8171b16 47 int main()
Ezeuz 4:9932af380e56 48 {
Ezeuz 4:9932af380e56 49 float meas = 0;
Ezeuz 4:9932af380e56 50 int snd = 0;
Ezeuz 4:9932af380e56 51
Ezeuz 4:9932af380e56 52 // Servos
Ezeuz 4:9932af380e56 53 for (int i = 1; i <= 20; i++) {
Ezeuz 4:9932af380e56 54 servos[i] = new Dynamixel(PC_6, PC_7, PC_4, i, 1000000);
Ezeuz 4:9932af380e56 55 }
dmgongora 0:79e2a8171b16 56
Ezeuz 4:9932af380e56 57 while (1) {
Ezeuz 4:9932af380e56 58 // LCD
Ezeuz 4:9932af380e56 59 lcd.printf("%.0f cm\n", meas);
Ezeuz 4:9932af380e56 60 lcd.printf("sound %d | uv %d", snd, uv.Flag);
Ezeuz 4:9932af380e56 61
Ezeuz 4:9932af380e56 62 // Servos
Ezeuz 4:9932af380e56 63 for (int i = 1; i <= 20; i++) {
Ezeuz 4:9932af380e56 64 servos[i]->setSpeed(100);
Ezeuz 4:9932af380e56 65 servos[i]->move(512); // Midddle, thus 90 deg position
Ezeuz 4:9932af380e56 66 }
Ezeuz 4:9932af380e56 67
Ezeuz 4:9932af380e56 68 // IR
Ezeuz 4:9932af380e56 69 meas = ir.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
Ezeuz 4:9932af380e56 70 meas = 5000000 / powf(meas, IR_CONST)+1;
Ezeuz 4:9932af380e56 71 lcd.printf("%.0f cm\n", meas);
Ezeuz 4:9932af380e56 72
Ezeuz 4:9932af380e56 73 // Extinguisher or 12V output
Ezeuz 4:9932af380e56 74 m2 = 1;
Ezeuz 4:9932af380e56 75 m1 = 1;
Ezeuz 4:9932af380e56 76
Ezeuz 4:9932af380e56 77 // LED
Ezeuz 4:9932af380e56 78 led1 = 1;
Ezeuz 4:9932af380e56 79 led2 = 1;
Ezeuz 4:9932af380e56 80
Ezeuz 4:9932af380e56 81 // Sound Activator
Ezeuz 4:9932af380e56 82 snd = sound.read();
Ezeuz 4:9932af380e56 83 }
dmgongora 0:79e2a8171b16 84 }