can publisher

Dependencies:   mbed mbed-STM32F103C8T6

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stm32f103c8t6.h"
00003 #define idc 2
00004 #define idp 3
00005 #define idw 4
00006 #define pi 3.141592653589793115997963468544185161590576171875
00007 #define speed_inc 0.20
00008 
00009 CAN can (PA_11, PA_12);
00010 Ticker copter;
00011 Ticker planer;
00012 Ticker wing;
00013 
00014 
00015 void tCopter(){
00016     static double i = 0;
00017     static double f;
00018     i += speed_inc;
00019     if (i > 2) i = 0;
00020     f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
00021     float send = static_cast<float>(f);
00022     can.write(CANMessage(idc, (char*)&send, sizeof(send)));
00023 }
00024 
00025 void tPlaner(){
00026     static double i = 0;
00027     static double f;
00028     i += speed_inc;
00029     if (i > 2) i = 0;
00030     f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
00031     float send = static_cast<float>(f);
00032     can.write(CANMessage(idp, (char*)&send, sizeof(send)));
00033 }
00034 
00035 void tWing(){
00036     static double i = 0;
00037     static double f;
00038     i += speed_inc;
00039     if (i > 2) i = 0;
00040     f = (sin(i * pi) + 1.0) / 2 + 1; //1..2
00041     float send = static_cast<float>(f);
00042     can.write(CANMessage(idw, (char*)&send, sizeof(send)));
00043 }
00044 
00045 int main() {
00046     confSysClock();
00047     wait(1);
00048     copter.attach(&tCopter, 0.1);
00049     wait(3);
00050     planer.attach(&tPlaner, 0.1);
00051     wait(3);
00052     wing.attach(&tWing, 0.1);
00053     while(1) {
00054         //os mbed 03
00055     }
00056     while(1) {
00057         //os mbed 03
00058     }
00059 }