35 #include <px4_platform_common/px4_config.h> 40 #include <uavcan/equipment/esc/RawCommand.hpp> 41 #include <uavcan/equipment/esc/RPMCommand.hpp> 42 #include <uavcan/equipment/esc/Status.hpp> 46 uavcan::Publisher<uavcan::equipment::esc::Status> *
pub_status;
49 unsigned self_index = 0;
52 static void cb_raw_command(
const uavcan::ReceivedDataStructure<uavcan::equipment::esc::RawCommand> &
msg)
54 if (msg.cmd.size() <= self_index) {
59 const float scaled = msg.cmd[self_index] / float(
65 ::syslog(LOG_INFO,
"scaled:%d\n", (
int)scaled);
73 static void cb_rpm_command(
const uavcan::ReceivedDataStructure<uavcan::equipment::esc::RPMCommand> &msg)
75 if (msg.rpm.size() <= self_index) {
79 rpm = msg.rpm[self_index];
83 ::syslog(LOG_INFO,
"rpm:%d\n", rpm);
94 void cb_10Hz(
const uavcan::TimerEvent &event)
96 uavcan::equipment::esc::Status
msg;
98 msg.esc_index = self_index;
101 msg.current = 0.001F;
102 msg.temperature = 24.0F;
103 msg.power_rating_pct =
static_cast<unsigned>(.5F * 100 + 0.5F);
108 static uavcan::MonotonicTime prev_pub_ts;
110 if ((event.scheduled_time - prev_pub_ts).toMSec() >= 990) {
111 prev_pub_ts =
event.scheduled_time;
124 typedef void (*cb)(
const uavcan::TimerEvent &);
125 static uavcan::Subscriber<uavcan::equipment::esc::RawCommand> sub_raw_command(node);
126 static uavcan::Subscriber<uavcan::equipment::esc::RPMCommand> sub_rpm_command(node);
127 static uavcan::TimerEventForwarder<cb> timer_10hz(node);
133 res = sub_raw_command.start(cb_raw_command);
139 res = sub_rpm_command.start(cb_rpm_command);
145 pub_status =
new uavcan::Publisher<uavcan::equipment::esc::Status>(node);
152 timer_10hz.setCallback(&cb_10Hz);
153 timer_10hz.startPeriodic(uavcan::MonotonicDuration::fromMSec(100));
uavcan::Publisher< uavcan::equipment::esc::Status > * pub_status
int init_sim_controller(uavcan::INode &node)
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
constexpr _Tp max(_Tp a, _Tp b)
void rgb_led(int r, int g, int b, int freqs)