AMK_motor_drive_software 1.0.0
Loading...
Searching...
No Matches
main.cpp File Reference
#include <Arduino.h>
#include <CANSAME5x.h>
#include "AMKUtils.hpp"
#include "Inverter.hpp"
#include "CANMessage.hpp"
#include "CANCommunication.hpp"
#include "DebugFlags.hpp"
#include "Potentiometer.hpp"

Functions

void setup ()
 
void loop ()
 
void initDevice ()
 Initializes the device settings, such as serial communication and CAN bus.
 
void startCANBus (long speed)
 Initializes the CAN bus with a given speed.
 
void receiveMessage (int packetSize)
 Callback function to handle received CAN messages.
 
bool sendMessage (CANMessage canMsg)
 Sends a CAN message over the CAN bus.
 
void updateInverter (uint16_t nodeAddress, uint16_t baseAddress, CANMessage canMsg)
 Updates inverter data based on received CAN message information.
 

Variables

CANSAME5x CAN
 
CANMessage canMsg
 
Inverter inverters [2]
 
Potentiometer pot
 

Function Documentation

◆ initDevice()

void initDevice ( )

Initializes the device settings, such as serial communication and CAN bus.

This function sets up the serial port and initializes the CAN bus at a specified baud rate.

◆ loop()

void loop ( )

◆ receiveMessage()

void receiveMessage ( int packetSize)

Callback function to handle received CAN messages.

Parameters
packetSizeThe size of the incoming packet.

Processes incoming CAN messages by extracting the CAN ID and data, updating inverter information, and handling errors for unknown nodes or invalid packet sizes.

◆ sendMessage()

bool sendMessage ( CANMessage canMsg)

Sends a CAN message over the CAN bus.

Parameters
canMsgThe CAN message object containing the ID and data to be sent.
Returns
true if the message was sent successfully; false otherwise.

Initiates the sending of a CAN message with the specified ID and data.

◆ setup()

void setup ( )

◆ startCANBus()

void startCANBus ( long speed)

Initializes the CAN bus with a given speed.

Parameters
speedThe CAN bus speed in bits per second (bps). For example, 500E3 for 500 kbps.

Configures the CAN bus speed and manages necessary pin settings to enable the CAN module. If initialization fails, an error message is displayed, and the built-in LED flashes.

◆ updateInverter()

void updateInverter ( uint16_t nodeAddress,
uint16_t baseAddress,
CANMessage canMsg )

Updates inverter data based on received CAN message information.

Parameters
nodeAddressThe address of the inverter node to be updated.
baseAddressThe base address used to identify the type of message.
canMsgThe CAN message containing the data to update the inverter.

Parses data from the received CAN message to update specific inverter parameters, such as status, velocity, and temperature.

Variable Documentation

◆ CAN

CANSAME5x CAN

◆ canMsg

CANMessage canMsg

◆ inverters

Inverter inverters[2]
Initial value:
= {
#define INVERTER_2_NODE_ADDRESS
Indirizzo nodo inverter 2.
Definition AMKUtils.hpp:12
#define INVERTER_1_NODE_ADDRESS
Inverters node addresses.
Definition AMKUtils.hpp:11
The Inverter class represents an inverter in the system, handling communication of actual values and ...
Definition Inverter.hpp:11

◆ pot