Skip to content

Commit ea03e37

Browse files
authored
#810 handle ELEC CAN debug frames and increase number of data points for filtered wind sensor moving average (#811)
* Safely ignore ELEC CAN debug frames * change number of data points for moving average to 20
1 parent 1c266dc commit ea03e37

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/network_systems/projects/can_transceiver/inc/can_frame_parser.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ enum class CanId : canid_t {
111111
PRESSURE_14 = 0x13E,
112112
PRESSURE_SENSOR_END = 0x13F,
113113
GENERIC_SENSOR_START = 0x140,
114-
GENERIC_SENSOR_END = 0x1FF
114+
GENERIC_SENSOR_END = 0x1FF,
115+
DEBUG_START = 0x200,
116+
DEBUG_END = 0x2FF
115117
};
116118

117119
inline bool isValidCanId(canid_t id)
@@ -135,7 +137,9 @@ inline bool isValidCanId(canid_t id)
135137
id <= static_cast<canid_t>(CanId::PRESSURE_SENSOR_END)) ||
136138

137139
(id >= static_cast<canid_t>(CanId::GENERIC_SENSOR_START) &&
138-
id <= static_cast<canid_t>(CanId::GENERIC_SENSOR_END));
140+
id <= static_cast<canid_t>(CanId::GENERIC_SENSOR_END)) ||
141+
142+
(id >= static_cast<canid_t>(CanId::DEBUG_START) && id <= static_cast<canid_t>(CanId::DEBUG_END));
139143
}
140144

141145
/**

src/network_systems/projects/can_transceiver/src/can_transceiver.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@ void CanTransceiver::onNewCanData(const CanFrame & frame) const
2727
return;
2828
}
2929
CanId id{frame.can_id};
30-
if (read_callbacks_.contains(id)) {
31-
read_callbacks_.at(id)(frame); // invoke the callback function mapped to id
30+
31+
if (id >= CanId::DEBUG_START && id <= CanId::DEBUG_END) {
32+
// ELEC debug frame, do nothing
33+
return;
3234
}
3335

3436
//0x100 - 0x1FF: Generic sensor data frame range
3537
if (id >= CanId::GENERIC_SENSOR_START && id <= CanId::GENERIC_SENSOR_END) {
3638
read_callbacks_.at(CanId::GENERIC_SENSOR_START)(frame);
39+
return;
40+
}
41+
42+
if (read_callbacks_.contains(id)) {
43+
read_callbacks_.at(id)(frame); // invoke the callback function mapped to id
44+
return;
3745
}
3846
}
3947

src/network_systems/projects/can_transceiver/src/can_transceiver_ros_intf.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ class CanTransceiverIntf : public NetNode
368368
wind_sensor_msg = wind_sensor.toRosMsg();
369369
wind_sensors_pub_->publish(wind_sensors_);
370370

371-
// NUM_WIND_SENSORS is a placeholder,
372-
// replace with number of data points wanted in the moving average
373-
double k = NUM_WIND_SENSORS;
371+
// Arbitrary number of data points for moving average
372+
double k = 20; //NOLINT(readability-magic-numbers)
374373
// convert deg to rad
375374
double angle = wind_sensor_msg.direction * (M_PI / 180.0); // NOLINT(readability-magic-numbers)
376375
double y = wind_sensor_msg.speed.speed * sin(angle);

0 commit comments

Comments
 (0)