pines

Dependencies:   HMC5883L111 RF24 RF24Network mbed motoresDC

Fork of RF24Network_Send by Akash Vibhute

Files at this revision

API Documentation at this revision

Comitter:
tabris2015
Date:
Fri Jun 10 22:16:34 2016 +0000
Parent:
3:d605536db315
Commit message:
pines maple;

Changed in this revision

HMC5883L.lib Show annotated file Show diff for this revision Revisions of this file
RF24.lib Show annotated file Show diff for this revision Revisions of this file
RF24Network.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
motoresDC.lib Show annotated file Show diff for this revision Revisions of this file
pines.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HMC5883L.lib	Fri Jun 10 22:16:34 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/tabris2015/code/HMC5883L111/#5a8279a48b30
--- a/RF24.lib	Thu Nov 05 05:59:18 2015 +0000
+++ b/RF24.lib	Fri Jun 10 22:16:34 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/akashvibhute/code/RF24/#e94be00fd19e
+http://developer.mbed.org/users/akashvibhute/code/RF24/#5cc7136648d1
--- a/RF24Network.lib	Thu Nov 05 05:59:18 2015 +0000
+++ b/RF24Network.lib	Fri Jun 10 22:16:34 2016 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/akashvibhute/code/RF24Network/#dfc8da7ac18c
+http://developer.mbed.org/users/akashvibhute/code/RF24Network/#b1110d26a900
--- a/main.cpp	Thu Nov 05 05:59:18 2015 +0000
+++ b/main.cpp	Fri Jun 10 22:16:34 2016 +0000
@@ -1,14 +1,20 @@
+#define MAPLE_MINI
+#include "pines.h"
 #include "mbed.h"
+#include <HMC5883L.h>
 #include <RF24Network.h>
 #include <RF24.h>
+#include <motoresDC.h>
 
-Serial pc(USBTX, USBRX);
+Serial pc(TX3_PIN, RX3_PIN);
+HMC5883L brujula;
+InterruptIn boton(PB_8);
 
-#define nrf_CE      D9
-#define nrf_CSN     D10
-#define spi_SCK     D3
-#define spi_MOSI    D4
-#define spi_MISO    D5
+//motores       D27   D31    D30    D26   D29    D28     
+MotoresDC carro(PWM_L, CTRL1_L, CTRL2_L, PWM_R, CTRL1_R, CTRL2_R);
+
+PwmOut led(PB_1);
+DigitalOut status(PB_2);
 
 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
 
@@ -17,66 +23,115 @@
 
 // Address of our node
 const uint16_t this_node = 01;
-
 // Address of the other node
 const uint16_t other_node = 00;
-
 // How often to send payload packet to the other unit
 const unsigned long interval = 100; //ms
-
 // When did we last send?
 unsigned long last_sent;
 Timer t;
-
 // How many have we sent already
 unsigned long packets_sent;
 Timer t_packet;
-
 // Structure of our payload
 struct payload_t 
 {
     unsigned long ms;
     unsigned long counter;
+    double heading;
 };
 
-
-int main()
+volatile double heading;
+volatile unsigned int flag = 0;
+// functions
+void toggle(void)
 {
-    pc.baud(921600);
+    flag = 1;
+    heading = brujula.getHeading();
+}
+
+void initP()
+{
+    led = 1;
+    boton.fall(toggle);
+    brujula.init();
+    carro.conducir(1);
     wait_ms(1000);
-
-    pc.printf("mBed RF24Network node: Tx\n");
+    carro.conducir(0);
+    led = 0;
+    wait_ms(500);
+    led = 1;
     radio.begin();
     network.begin(/*channel*/ 90, /*node address*/ this_node);
+    carro.conducir(-1);
     wait_ms(2000);
     t.start();
     t_packet.start();
+    status = 0;
+    led = 0;
+    carro.conducir(0);
+}
+
+void checkMessage()
+{
+    while ( network.available() ) 
+        {
+            // If so, grab it and print it out
+            RF24NetworkHeader header_rx;
+            payload_t payload_rx;
+            network.read(header_rx,&payload_rx,sizeof(payload_rx));
+            carro.conducir(payload_rx.heading / 360.0);
+            status = abs(payload_rx.heading) < 5.0 ? 1 : 0;
+        }
+}
+//------
+
+bool sendMessage(double angulo)
+{
+    led = !led;
+            t.reset();
+
+            payload_t payload_tx;
+            payload_tx.ms = t_packet.read_ms();
+            payload_tx.counter = packets_sent++;
+            payload_tx.heading = angulo;
+            
+            RF24NetworkHeader header_tx(/*to node*/ other_node);
+            bool ok = network.write(header_tx,&payload_tx,sizeof(payload_tx));    
+            flag = 0;
+            led = 0;     
+            return ok;
+}    
+int main()
+{   
+    initP();
+    
+    
     while(1) 
     {
         // Pump the network regularly
         network.update();
-
+        checkMessage();
         /* If it's time to send a message, send it! */
+        double angulo = brujula.getHeading();
+        led = angulo / 360.0;
         unsigned long now = t.read_ms();
-        if ( now >= interval  ) 
+        if ( (now - last_sent) > interval  ) 
         {
-            t.reset();
-
-            pc.printf("Sending...");
-            payload_t payload_tx;
-            payload_tx.ms = t_packet.read_ms();
-            payload_tx.counter = packets_sent++;
-
-
-            RF24NetworkHeader header_tx(/*to node*/ other_node);
-            bool ok = network.write(header_tx,&payload_tx,sizeof(payload_tx));
-            if (ok)
-                pc.printf("ok.\n");
-            else
-                pc.printf("failed.\n");
+            last_sent = now;
+            bool ok = sendMessage(angulo);
         }
-
-
+        
+        /*
+        if(abs(angulo) < 4)
+        {
+            led = 1;
+        }
+        else
+        {
+            led = 0;
+        }
+        */
     }
 
 }
\ No newline at end of file
--- a/mbed.bld	Thu Nov 05 05:59:18 2015 +0000
+++ b/mbed.bld	Fri Jun 10 22:16:34 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/motoresDC.lib	Fri Jun 10 22:16:34 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/tabris2015/code/motoresDC/#5715aefb07ca
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pines.h	Fri Jun 10 22:16:34 2016 +0000
@@ -0,0 +1,28 @@
+#ifdef MAPLE_MINI
+// pines para los motores
+    
+// Pines para el driver de motores
+#define PWM_L   PA_8        // d27
+#define CTRL1_L PB_12       // d31
+#define CTRL2_L PB_13       // d30
+#define PWM_R   PA_9        // d26
+#define CTRL1_R PB_14       // d29
+#define CTRL2_R PB_15       // d28
+
+// pines para el rf
+
+#define nrf_CE      PA_3
+#define nrf_CSN     PA_4
+#define spi_SCK     PA_5
+#define spi_MOSI    PA_7
+#define spi_MISO    PA_6
+
+// pines para el puerto serial
+#define TX3_PIN     PB_10
+#define RX3_PIN     PB_11
+
+
+// pines para bus I2C
+#define SDA_PIN     PB_7
+#define SCL_PIN     PB_6
+#endif
\ No newline at end of file