Руслан Урядинский / Mbed 2 deprecated UAVCAN_Subscriber

Dependencies:   libuavcan mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "chip.h"
00003 #include "libuavcan/libuavcan/include/uavcan/build_config.hpp" //All default configuration options
00004 #include "libuavcan/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp" //OS detection; Any General-Purpose timer
00005 #include "libuavcan/libuavcan/include/uavcan/node/subscriber.hpp" //Subscriber class
00006 #include <uavcan/equipment/actuator/Command.hpp> //message type
00007 #include "stm32f103c8t6.h"
00008 
00009 
00010 static PwmOut servo(PA_8);
00011 void move ();
00012 
00013 extern uavcan::ICanDriver& getCanDriver();
00014 extern uavcan::ISystemClock& getSystemClock();
00015 
00016 const unsigned NodeMemoryPoolSize = 16384; // Need calulate (tutorial 2).
00017 typedef uavcan::Node<NodeMemoryPoolSize> Node;
00018 
00019 static Node& getNode() {
00020     static Node node(getCanDriver(), getSystemClock());
00021     return node;
00022 }
00023 
00024 int main() {
00025     confSysClock();
00026     auto& node = getNode();
00027     node.setNodeID(2);
00028     node.setName("Actuator");
00029     if (node.start() > 0){ //<>?
00030         //обработка ошибок запуска
00031     }
00032     uavcan::Subscriber <uavcan::equipment::actuator::Command> sub(node); //define node to subscriber
00033     if (sub.start(move) > 0) { //запуск чтения
00034         //обработка ошибок
00035     }
00036     
00037     node.setMoreOptional();
00038     float input = 0;
00039     while(1) {
00040         if (node.spin(uavcan::MonotonicDuration::getInfinite()) < 0){
00041             //обработчик ошибок
00042         }
00043     }
00044 }
00045 
00046 void move (const ReceivedDataStructure<DataType_>& msg){
00047     static bool a = true;
00048     if(a){
00049         servo.period_ms(20);
00050         a = false;
00051     }
00052     servo = (msg.command_value / pi) / 2 + 1 //лучше перевести это в коэффициент
00053 }