-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mtc Nucleo board connection #115
Open
TomLonergan03
wants to merge
31
commits into
master
Choose a base branch
from
mtc-frequency_gen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
34e1877
Started frequency sender
TomLonergan03 0c753ff
Added STM CAN data frame
TomLonergan03 f4ac389
STM CAN sender
TomLonergan03 9c46d21
Rename stm to nucleo
TomLonergan03 0a16c38
Moved nucleo management to new class
TomLonergan03 dea68a6
Splitting out can sender from transceiver
TomLonergan03 cd8c79b
Split sender and transceiver
TomLonergan03 8d64707
Added nucleo frequency sender
TomLonergan03 b3dccab
Fixes
TomLonergan03 df754b2
Revert logger changes
TomLonergan03 49067e8
replaced int division with rounding
TomLonergan03 7d3024c
Moved nucleo manager to unique ptr
TomLonergan03 492b3bd
Nucleo manager owns own logger
TomLonergan03 59e4882
Changed all loggers to new style
TomLonergan03 546f159
Removed unused is_sending from non-fake can system
TomLonergan03 0084ef8
Can sender owns can instance, transceiver inherits from sender
TomLonergan03 3538b73
Moved nucleo_manager_ construction
TomLonergan03 966a5b2
Can transceiver is dead, long live can receiver
TomLonergan03 fbf3c25
Renamed CAN interfaces
TomLonergan03 dc8ad4a
Reorder and cleanup can ids
TomLonergan03 01f1fe1
Consts
TomLonergan03 e3fb1ab
Clarified casting
TomLonergan03 0744837
Arrays start at 0
TomLonergan03 b926539
Moved include statements
TomLonergan03 c6fb226
Fixes
TomLonergan03 bf038ca
Removed unused ids
TomLonergan03 b7948a3
Minor fixes
TomLonergan03 07c6652
Fix merge conflicts
TomLonergan03 42799b4
Merge branch 'master' into mtc-frequency_gen
TomLonergan03 3d4e3a8
Spelling
TomLonergan03 f3dd33f
Fixing merge issues
TomLonergan03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#include <stdint.h> | ||
|
||
#include <array> | ||
namespace hyped { | ||
|
||
namespace propulsion { | ||
|
||
// Types of CANopen messages, these are used for CAN ID's | ||
static constexpr uint32_t kNmtReceive = 0x000; | ||
static constexpr uint32_t kEmgyTransmit = 0x80; | ||
static constexpr uint32_t kPdo1Transmit = 0x180; | ||
static constexpr uint32_t kPdo1Receive = 0x200; | ||
static constexpr uint32_t kPdo2Transmit = 0x280; | ||
static constexpr uint32_t kPdo2Receive = 0x300; | ||
static constexpr uint32_t kPdo3Transmit = 0x380; | ||
static constexpr uint32_t kPdo3Receive = 0x400; | ||
static constexpr uint32_t kPdo4Transmit = 0x480; | ||
static constexpr uint32_t kPdo4Receive = 0x500; | ||
static constexpr uint32_t kSdoTransmit = 0x580; | ||
static constexpr uint32_t kSdoReceive = 0x600; | ||
static constexpr uint32_t kNmtTransmit = 0x700; | ||
static constexpr uint32_t kNucleoTransmit = 0x900; // currently lowest priority, might change | ||
|
||
static constexpr std::array<uint32_t, 14> kCanIds | ||
= {kNmtReceive, kEmgyTransmit, kPdo1Transmit, kPdo1Receive, kPdo2Transmit, | ||
kPdo2Receive, kPdo3Transmit, kPdo3Receive, kPdo4Transmit, kPdo4Receive, | ||
kSdoTransmit, kSdoReceive, kNmtTransmit, kNucleoTransmit}; | ||
|
||
} // namespace propulsion | ||
} // namespace hyped |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "can_receiver.hpp" | ||
|
||
namespace hyped::propulsion { | ||
|
||
CanReceiver::CanReceiver(const uint8_t node_id, IController &controller) | ||
: log_("CAN-TRANSCEIVER", utils::System::getSystem().config_.log_level_propulsion), | ||
node_id_(node_id), | ||
controller_(controller), | ||
can_(utils::io::Can::getInstance()) | ||
{ | ||
can_.start(); | ||
} | ||
|
||
void CanReceiver::registerController() | ||
{ | ||
can_.registerProcessor(this); | ||
} | ||
|
||
void CanReceiver::processNewData(utils::io::can::Frame &message) | ||
{ | ||
uint32_t id = message.id; | ||
if (id == kEmgyTransmit + node_id_) { | ||
controller_.processEmergencyMessage(message); | ||
} else if (id == kSdoTransmit + node_id_) { | ||
controller_.processSdoMessage(message); | ||
} else if (id == kNmtTransmit + node_id_) { | ||
controller_.processNmtMessage(message); | ||
} else { | ||
log_.error("Controller %d: CAN message not recognised", node_id_); | ||
} | ||
} | ||
|
||
bool CanReceiver::hasId(const uint32_t id, bool) | ||
TomLonergan03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
for (uint32_t cobId : kCanIds) { | ||
if (cobId + node_id_ == id) { return true; } | ||
} | ||
return false; | ||
} | ||
} // namespace hyped::propulsion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "can_ids.hpp" | ||
#include "receiver_interface.hpp" | ||
|
||
#include <atomic> | ||
#include <iostream> | ||
|
||
#include <propulsion/controller_interface.hpp> | ||
#include <utils/concurrent/thread.hpp> | ||
#include <utils/io/can.hpp> | ||
#include <utils/logger.hpp> | ||
#include <utils/system.hpp> | ||
|
||
namespace hyped::propulsion { | ||
|
||
class CanReceiver : public utils::io::CanProccesor, public ICanReceiver { | ||
public: | ||
/** | ||
* @brief Initialise the CanReceiver with the id and the controller as an | ||
* attribute, to access it's attributes | ||
*/ | ||
CanReceiver(const uint8_t node_id, IController &controller); | ||
|
||
/** | ||
* @brief Registers the controller to process incoming CAN messages | ||
*/ | ||
void registerController() override; | ||
|
||
/** | ||
* @brief This function processes incoming CAN messages | ||
*/ | ||
void processNewData(utils::io::can::Frame &message) override; | ||
|
||
/** | ||
* @brief If this function returns true, the CAN message is ment for this CAN node | ||
*/ | ||
bool hasId(const uint32_t id, bool extended) override; | ||
TomLonergan03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private: | ||
utils::Logger log_; | ||
uint8_t node_id_; | ||
utils::io::Can &can_; | ||
IController &controller_; | ||
|
||
static constexpr uint64_t kTimeout = 70000; // us | ||
TomLonergan03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
} // namespace hyped::propulsion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,16 @@ | ||
#include "can_sender.hpp" | ||
|
||
#include <utils/timer.hpp> | ||
|
||
namespace hyped::propulsion { | ||
|
||
CanSender::CanSender(utils::Logger &log, const uint8_t node_id, IController &controller) | ||
: log_(log), | ||
node_id_(node_id), | ||
can_(utils::io::Can::getInstance()), | ||
controller_(controller) | ||
CanSender::CanSender() | ||
: log_("CAN-SENDER", utils::System::getSystem().config_.log_level_propulsion), | ||
can_(utils::io::Can::getInstance()) | ||
{ | ||
is_sending_ = false; | ||
can_.start(); | ||
} | ||
|
||
bool CanSender::sendMessage(utils::io::can::Frame &message) | ||
bool CanSender::sendMessage(const utils::io::can::Frame &message) | ||
{ | ||
log_.info("Sending Message"); | ||
can_.send(message); | ||
is_sending_ = true; | ||
const auto now = utils::Timer::getTimeMicros(); | ||
while (is_sending_) { | ||
if ((utils::Timer::getTimeMicros() - now) > kTimeout) { | ||
// TODO(Iain): Test the latency and set the TIMEOUT to a reasonable value. | ||
log_.error("Sender timeout reached"); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
void CanSender::registerController() | ||
{ | ||
can_.registerProcessor(this); | ||
} | ||
|
||
void CanSender::processNewData(utils::io::can::Frame &message) | ||
{ | ||
is_sending_ = false; | ||
uint32_t id = message.id; | ||
if (id == kEmgyTransmit + node_id_) { | ||
controller_.processEmergencyMessage(message); | ||
} else if (id == kSdoTransmit + node_id_) { | ||
controller_.processSdoMessage(message); | ||
} else if (id == kNmtTransmit + node_id_) { | ||
controller_.processNmtMessage(message); | ||
} else { | ||
log_.error("Controller %d: CAN message not recognised", node_id_); | ||
} | ||
} | ||
|
||
bool CanSender::hasId(uint32_t id, bool) | ||
{ | ||
for (uint32_t cobId : canIds) { | ||
if (cobId + node_id_ == id) { return true; } | ||
} | ||
return false; | ||
} | ||
|
||
bool CanSender::getIsSending() | ||
{ | ||
return is_sending_; | ||
return can_.send(message); | ||
} | ||
} // namespace hyped::propulsion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "fake_can_receiver.hpp" | ||
|
||
namespace hyped::propulsion { | ||
FakeCanReceiver::FakeCanReceiver(uint8_t) | ||
TomLonergan03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: log_("FAKE-CAN-SENDER", utils::System::getSystem().config_.log_level_propulsion), | ||
is_sending_(false), | ||
can_endpoint_(*this) | ||
{ | ||
} | ||
|
||
void FakeCanReceiver::registerController() | ||
{ | ||
} | ||
|
||
void FakeCanReceiver::processNewData(utils::io::can::Frame &) | ||
{ | ||
log_.info("processNewData"); | ||
is_sending_ = false; | ||
} | ||
|
||
bool FakeCanReceiver::hasId(const uint32_t, bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not passing in any arguments? |
||
{ | ||
return true; | ||
} | ||
|
||
bool FakeCanReceiver::getIsSending() | ||
{ | ||
return is_sending_; | ||
} | ||
} // namespace hyped::propulsion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include "fake_can_endpoint.hpp" | ||
#include "receiver_interface.hpp" | ||
|
||
#include <atomic> | ||
#include <iostream> | ||
|
||
#include <utils/io/can.hpp> | ||
#include <utils/logger.hpp> | ||
#include <utils/system.hpp> | ||
|
||
namespace hyped::propulsion { | ||
|
||
class FakeCanReceiver : public utils::io::CanProccesor, public ICanReceiver { | ||
public: | ||
FakeCanReceiver(uint8_t id); | ||
|
||
void registerController() override; | ||
|
||
void processNewData(utils::io::can::Frame &message) override; | ||
|
||
bool hasId(const uint32_t id, bool extended) override; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment here why the boolean isn't used? |
||
|
||
bool getIsSending(); | ||
|
||
private: | ||
utils::Logger log_; | ||
// Can& can_; | ||
std::atomic<bool> is_sending_; | ||
FakeCanEndpoint can_endpoint_; | ||
}; | ||
|
||
} // namespace hyped::propulsion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we ensure that there are no conflicts here? Do we limit node IDs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each node_id_ is numbered from 0 and there is one node for each motor controller so we won't have one overflow unless we have 21 motor controllers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know the BMS is not using these nodes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BMS starts at node 300 as far as i can tell