Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:16f48f8c7ad3
- Parent:
- 0:14b95d68acf6
diff -r 14b95d68acf6 -r 16f48f8c7ad3 main.cpp
--- a/main.cpp Thu May 10 15:08:30 2018 +0000
+++ b/main.cpp Sat May 12 09:00:17 2018 +0000
@@ -3,8 +3,12 @@
#include "libuavcan/libuavcan/include/uavcan/build_config.hpp" //All default configuration options
#include "libuavcan/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp" //OS detection; Any General-Purpose timer
#include "libuavcan/libuavcan/include/uavcan/node/subscriber.hpp" //Subscriber class
+#include <uavcan/equipment/actuator/Command.hpp> //message type
+#include "stm32f103c8t6.h"
-#include <uavcan/equipment/actuator/Command.hpp> //message type
+
+static PwmOut servo(PA_8);
+void move ();
extern uavcan::ICanDriver& getCanDriver();
extern uavcan::ISystemClock& getSystemClock();
@@ -18,22 +22,32 @@
}
int main() {
+ confSysClock();
auto& node = getNode();
node.setNodeID(2);
node.setName("Actuator");
if (node.start() > 0){ //<>?
//обработка ошибок запуска
}
- uavcan::Subscriber <uavcan::equipment::actuator::Command> sub(node); //define node to publisher
- if (sub.start() > 0) { //инициализация паблишера
+ uavcan::Subscriber <uavcan::equipment::actuator::Command> sub(node); //define node to subscriber
+ if (sub.start(move) > 0) { //запуск чтения
//обработка ошибок
}
node.setMoreOptional();
+ float input = 0;
while(1) {
if (node.spin(uavcan::MonotonicDuration::getInfinite()) < 0){
//обработчик ошибок
}
-
}
}
+
+void move (const ReceivedDataStructure<DataType_>& msg){
+ static bool a = true;
+ if(a){
+ servo.period_ms(20);
+ a = false;
+ }
+ servo = (msg.command_value / pi) / 2 + 1 //лучше перевести это в коэффициент
+}
\ No newline at end of file