27#include "isobus/utility/system_timing.hpp" 
   38                                                                 std::shared_ptr<ControlFunction> destination,
 
   39                                                                 bool enableSendingSystemCommandPeriodically,
 
   40                                                                 bool enableSendingMachineInfoPeriodically) :
 
   41      guidanceMachineInfoTransmitData(
GuidanceMachineInfo(enableSendingMachineInfoPeriodically ? source : nullptr)),
 
   42      guidanceSystemCommandTransmitData(
GuidanceSystemCommand(enableSendingSystemCommandPeriodically ? source : nullptr)),
 
   43      txFlags(static_cast<std::uint32_t>(
TransmitFlags::NumberOfFlags), process_flags, this),
 
   44      destinationControlFunction(destination)
 
 
   58      controlFunction(sender)
 
 
   64        if (commandedStatus != newStatus)
 
   66            commandedStatus = newStatus;
 
 
   74        return commandedStatus;
 
 
   79        if (std::fabs(commandedCurvature - curvature) > std::numeric_limits<float>::epsilon())
 
   81            commandedCurvature = curvature;
 
 
   89        return commandedCurvature;
 
 
   94        return controlFunction;
 
 
   99        timestamp_ms = timestamp;
 
 
  108      controlFunction(sender)
 
 
  114        if (std::fabs(estimatedCurvature - curvature) > std::numeric_limits<float>::epsilon())
 
  116            estimatedCurvature = curvature;
 
 
  124        return estimatedCurvature;
 
 
  129        if (mechanicalSystemLockoutState != state)
 
  131            mechanicalSystemLockoutState = state;
 
 
  139        return mechanicalSystemLockoutState;
 
 
  144        if (guidanceSteeringSystemReadinessState != state)
 
  146            guidanceSteeringSystemReadinessState = state;
 
 
  154        return guidanceSteeringSystemReadinessState;
 
 
  159        if (guidanceSteeringInputPositionStatus != state)
 
  161            guidanceSteeringInputPositionStatus = state;
 
 
  169        return guidanceSteeringInputPositionStatus;
 
 
  174        if (requestResetCommandStatus != state)
 
  176            requestResetCommandStatus = state;
 
 
  184        return requestResetCommandStatus;
 
 
  189        if (guidanceLimitStatus != status)
 
  191            guidanceLimitStatus = status;
 
 
  199        return guidanceLimitStatus;
 
 
  204        if (guidanceSystemCommandExitReasonCode != exitCode)
 
  206            guidanceSystemCommandExitReasonCode = exitCode;
 
 
  214        return guidanceSystemCommandExitReasonCode;
 
 
  219        if (guidanceSystemRemoteEngageSwitchStatus != switchStatus)
 
  221            guidanceSystemRemoteEngageSwitchStatus = switchStatus;
 
 
  229        return guidanceSystemRemoteEngageSwitchStatus;
 
 
  234        return controlFunction;
 
 
  239        timestamp_ms = timestamp;
 
 
  254                LOG_WARNING(
"[Guidance]: Use extreme caution! You have configured the ISOBUS guidance interface with the ability to steer a machine.");
 
 
  279        std::shared_ptr<AgriculturalGuidanceInterface::GuidanceMachineInfo> retVal = 
nullptr;
 
 
  290        std::shared_ptr<AgriculturalGuidanceInterface::GuidanceSystemCommand> retVal = 
nullptr;
 
 
  321                LOG_WARNING(
"[Guidance]: Transmitting a commanded curvature clamped to maximum value. Verify guidance calculations are accurate!");
 
  323            else if (scaledCurvature < 0) 
 
  325                encodedCurvature = 0; 
 
  326                LOG_WARNING(
"[Guidance]: Transmitting a commanded curvature clamped to minimum value. Verify guidance calculations are accurate!");
 
  330                encodedCurvature = 
static_cast<std::uint16_t
>(scaledCurvature);
 
  333            std::array<std::uint8_t, CAN_DATA_LENGTH> buffer = { 
static_cast<std::uint8_t
>(encodedCurvature & 0xFF),
 
  334                                                                   static_cast<std::uint8_t
>((encodedCurvature >> 8) & 0xFF),
 
 
  364                LOG_WARNING(
"[Guidance]: Transmitting an estimated curvature clamped to maximum value. Verify guidance calculations are accurate!");
 
  366            else if (scaledCurvature < 0) 
 
  368                encodedCurvature = 0; 
 
  369                LOG_WARNING(
"[Guidance]: Transmitting an estimated curvature clamped to minimum value. Verify guidance calculations are accurate!");
 
  373                encodedCurvature = 
static_cast<std::uint16_t
>(scaledCurvature);
 
  376            std::array<std::uint8_t, CAN_DATA_LENGTH> buffer = {
 
  377                static_cast<std::uint8_t
>(encodedCurvature & 0xFF),
 
  378                static_cast<std::uint8_t
>((encodedCurvature >> 8) & 0xFF),
 
 
  407                                                                     [](std::shared_ptr<GuidanceMachineInfo> guidanceInfo) {
 
  408                                                                         return SystemTiming::time_expired_ms(guidanceInfo->get_timestamp_ms(), GUIDANCE_MESSAGE_TIMEOUT_MS);
 
  413                                                                       [](std::shared_ptr<GuidanceSystemCommand> guidanceCommand) {
 
  414                                                                           return SystemTiming::time_expired_ms(guidanceCommand->get_timestamp_ms(), GUIDANCE_MESSAGE_TIMEOUT_MS);
 
  434            LOG_ERROR(
"[Guidance]: Guidance interface has not been initialized yet.");
 
 
  440        if (
nullptr != parentPointer)
 
  443            bool transmitSuccessful = 
false;
 
  449                    transmitSuccessful = targetInterface->send_guidance_machine_info();
 
  455                    transmitSuccessful = targetInterface->send_guidance_system_command();
 
  463            if (
false == transmitSuccessful)
 
  465                targetInterface->txFlags.set_flag(flag);
 
 
  472        assert(
nullptr != parentPointer);
 
  477            case static_cast<std::uint32_t
>(CANLibParameterGroupNumber::AgriculturalGuidanceSystemCommand):
 
  483                        auto result = std::find_if(targetInterface->receivedGuidanceSystemCommandMessages.begin(),
 
  484                                                   targetInterface->receivedGuidanceSystemCommandMessages.end(),
 
  485                                                   [&message](
const std::shared_ptr<GuidanceSystemCommand> &receivedCommand) {
 
  486                                                       return (nullptr != receivedCommand) && (receivedCommand->get_sender_control_function() == message.get_source_control_function());
 
  489                        if (result == targetInterface->receivedGuidanceSystemCommandMessages.end())
 
  492                            targetInterface->receivedGuidanceSystemCommandMessages.push_back(std::make_shared<GuidanceSystemCommand>(message.
get_source_control_function()));
 
  493                            result = targetInterface->receivedGuidanceSystemCommandMessages.end() - 1;
 
  496                        auto guidanceCommand = *result;
 
  497                        bool changed = 
false;
 
  501                        guidanceCommand->set_timestamp_ms(SystemTiming::get_timestamp_ms());
 
  503                        targetInterface->guidanceSystemCommandEventPublisher.call(guidanceCommand, changed);
 
  508                    LOG_WARNING(
"[Guidance]: Received a malformed guidance system command message. DLC must be 8.");
 
  513            case static_cast<std::uint32_t
>(CANLibParameterGroupNumber::AgriculturalGuidanceMachineInfo):
 
  519                        auto result = std::find_if(targetInterface->receivedGuidanceMachineInfoMessages.cbegin(),
 
  520                                                   targetInterface->receivedGuidanceMachineInfoMessages.cend(),
 
  521                                                   [&message](
const std::shared_ptr<GuidanceMachineInfo> &receivedInfo) {
 
  522                                                       return (nullptr != receivedInfo) && (receivedInfo->get_sender_control_function() == message.get_source_control_function());
 
  525                        if (result == targetInterface->receivedGuidanceMachineInfoMessages.cend())
 
  528                            targetInterface->receivedGuidanceMachineInfoMessages.push_back(std::make_shared<GuidanceMachineInfo>(message.
get_source_control_function()));
 
  529                            result = targetInterface->receivedGuidanceMachineInfoMessages.cend() - 1;
 
  532                        auto machineInfo = *result;
 
  533                        bool changed = 
false;
 
  541                        changed |= machineInfo->set_guidance_system_command_exit_reason_code(message.
get_uint8_at(4) & 0x3F);
 
  543                        machineInfo->set_timestamp_ms(SystemTiming::get_timestamp_ms());
 
  545                        targetInterface->guidanceMachineInfoEventPublisher.call(machineInfo, changed);
 
  550                    LOG_WARNING(
"[Guidance]: Received a malformed guidance machine info message. DLC must be 8.");
 
 
Defines some PGNs that are used in the library or are very common.
 
An abstraction of a CAN message, could be > 8 data bytes.
 
The main class that manages the ISOBUS stack including: callbacks, Name to Address management,...
 
A class that acts as a logging sink. The intent is that someone could make their own derived class of...
 
An interface for sending and receiving the ISOBUS agricultural guidance machine message.
 
bool set_guidance_steering_system_readiness_state(GenericSAEbs02SlotValue state)
Sets the guidance system's readiness state to report.
 
bool set_guidance_system_command_exit_reason_code(std::uint8_t exitCode)
Sets the exit code for the guidance system.
 
std::shared_ptr< ControlFunction > get_sender_control_function() const
Returns a pointer to the sender of the message. If an ICF is the sender, returns the ICF being used t...
 
RequestResetCommandStatus get_request_reset_command_status() const
Returns the reported request reset command.
 
GenericSAEbs02SlotValue get_guidance_steering_system_readiness_state() const
Returns the guidance system's readiness state for steering.
 
GenericSAEbs02SlotValue get_guidance_system_remote_engage_switch_status() const
Returns the state for the steering engage switch.
 
GuidanceLimitStatus
This parameter is used to report the steering system's present limit status associated with guidance ...
 
GenericSAEbs02SlotValue
A typical, generic 2 bit value in J1939 with no superseding definition in ISO 11783.
 
bool set_mechanical_system_lockout_state(MechanicalSystemLockout state)
Sets the mechanical system lockout state.
 
std::uint32_t get_timestamp_ms() const
Returns the timestamp for when the message was received, in milliseconds.
 
float get_estimated_curvature() const
Returns the estimated curvature that was previously set with set_estimated_curvature.
 
bool set_guidance_system_remote_engage_switch_status(GenericSAEbs02SlotValue switchStatus)
Sets the state for the steering engage switch.
 
bool set_request_reset_command_status(RequestResetCommandStatus state)
Sets the request reset command to report.
 
bool set_guidance_limit_status(GuidanceLimitStatus status)
Sets the reported guidance limit status.
 
GenericSAEbs02SlotValue get_guidance_steering_input_position_status() const
Returns the guidance steering input position state.
 
bool set_estimated_curvature(float curvature)
Sets the estimated course curvature over ground for the machine.
 
MechanicalSystemLockout get_mechanical_system_lockout() const
Returns the mechanical system lockout state.
 
MechanicalSystemLockout
State of a lockout switch that allows operators to disable automatic steering system functions.
 
void set_timestamp_ms(std::uint32_t timestamp)
Sets the timestamp for when the message was received or sent.
 
RequestResetCommandStatus
Machine steering system request to the automatic guidance system to change Curvature Command Status s...
 
GuidanceLimitStatus get_guidance_limit_status() const
Returns the reported guidance limit status.
 
std::uint8_t get_guidance_system_command_exit_reason_code() const
Returns the exit code for the guidance system.
 
GuidanceMachineInfo(std::shared_ptr< ControlFunction > sender)
Constructor for a GuidanceMachineInfo.
 
bool set_guidance_steering_input_position_status(GenericSAEbs02SlotValue state)
Sets the guidance steering input position state.
 
An interface for sending the agricultural guidance system command message.
 
bool set_curvature(float curvature)
Desired course curvature over ground that a machine's steering system is required to achieve.
 
CurvatureCommandStatus get_status() const
Returns the curvature command status that is active in the guidance system.
 
std::uint32_t get_timestamp_ms() const
Returns the timestamp for when the message was received, in milliseconds.
 
bool set_status(CurvatureCommandStatus newStatus)
Sets the curvature command status that will be encoded into the CAN message. This parameter indicates...
 
float get_curvature() const
Returns the curvature value that is currently be trying to be achieved by the guidance system.
 
GuidanceSystemCommand(std::shared_ptr< ControlFunction > sender)
Constructor for a GuidanceSystemCommand.
 
void set_timestamp_ms(std::uint32_t timestamp)
Sets the timestamp for when the message was received or sent.
 
std::shared_ptr< ControlFunction > get_sender_control_function() const
Returns a pointer to the sender of the message. If an ICF is the sender, returns the ICF being used t...
 
CurvatureCommandStatus
This parameter indicates whether the guidance system is attempting to control steering with this comm...
 
An interface for sending and receiving ISOBUS guidance messages.
 
GuidanceSystemCommand guidanceSystemCommandTransmitData
Use this to configure transmission the guidance system command message from your application....
 
EventDispatcher< const std::shared_ptr< GuidanceMachineInfo >, bool > & get_guidance_machine_info_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated guidance machine info...
 
void update()
Call this cyclically to update the interface. Transmits messages if needed and processes timeouts for...
 
ProcessingFlags txFlags
Tx flag for sending messages periodically.
 
void initialize()
Sets up the class and registers it to receive callbacks from the network manager for processing guida...
 
AgriculturalGuidanceInterface(std::shared_ptr< InternalControlFunction > source, std::shared_ptr< ControlFunction > destination, bool enableSendingSystemCommandPeriodically=false, bool enableSendingMachineInfoPeriodically=false)
Constructor for a AgriculturalGuidanceInterface.
 
EventDispatcher< const std::shared_ptr< GuidanceSystemCommand >, bool > & get_guidance_system_command_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated guidance system comma...
 
std::uint32_t guidanceSystemCommandTransmitTimestamp_ms
Timestamp used to know when to transmit the guidance system command message.
 
static constexpr float CURVATURE_COMMAND_MAX_INVERSE_KM
The maximum curvature that can be encoded once scaling is applied.
 
bool get_initialized() const
Returns if the interface has been initialized.
 
EventDispatcher< const std::shared_ptr< GuidanceSystemCommand >, bool > guidanceSystemCommandEventPublisher
An event publisher for notifying when new guidance system commands are received.
 
EventDispatcher< const std::shared_ptr< GuidanceMachineInfo >, bool > guidanceMachineInfoEventPublisher
An event publisher for notifying when new guidance machine info messages are received.
 
static constexpr float CURVATURE_COMMAND_OFFSET_INVERSE_KM
Constant offset for curvature being sent on the bus in km-1.
 
static void process_flags(std::uint32_t flag, void *parentPointer)
Processes one flag (which sends the associated message)
 
std::shared_ptr< GuidanceSystemCommand > get_received_guidance_system_command(std::size_t index)
Returns the content of the agricultural guidance curvature command message based on the index of the ...
 
static constexpr float CURVATURE_COMMAND_RESOLUTION_PER_BIT
The resolution of the message in km-1 per bit.
 
bool send_guidance_system_command() const
Sends the agricultural guidance system command message based on the configured content of guidanceSys...
 
std::vector< std::shared_ptr< GuidanceSystemCommand > > receivedGuidanceSystemCommandMessages
A list of all received curvature commands and statuses.
 
bool send_guidance_machine_info() const
Sends the agricultural guidance machine info message based on the configured content of guidanceMachi...
 
static void process_rx_message(const CANMessage &message, void *parentPointer)
Processes a CAN message.
 
std::uint32_t guidanceMachineInfoTransmitTimestamp_ms
Timestamp used to know when to transmit the guidance machine info message.
 
std::vector< std::shared_ptr< GuidanceMachineInfo > > receivedGuidanceMachineInfoMessages
A list of all received estimated curvatures.
 
TransmitFlags
Enumerates a set of flags to manage transmitting messages owned by this interface.
 
@ SendGuidanceSystemCommand
A flag to manage sending the guidance system command message.
 
@ SendGuidanceMachineInfo
A flag to manage sending the guidance machine info message.
 
std::size_t get_number_received_guidance_system_command_sources() const
Returns the number of received, unique guidance system command sources.
 
std::shared_ptr< ControlFunction > destinationControlFunction
The optional destination to which messages will be sent. If nullptr it will be broadcast instead.
 
bool initialized
Stores if the interface has been initialized.
 
std::size_t get_number_received_guidance_machine_info_message_sources() const
Returns the number of received, unique guidance machine info message sources.
 
static constexpr std::uint16_t ZERO_CURVATURE_INVERSE_KM
This is the value for zero km-1 for 0.25 km-1 per bit.
 
~AgriculturalGuidanceInterface()
Destructor for the AgriculturalGuidanceInterface.
 
std::shared_ptr< GuidanceMachineInfo > get_received_guidance_machine_info(std::size_t index)
Returns the content of the agricultural guidance machine info message based on the index of the sende...
 
GuidanceMachineInfo guidanceMachineInfoTransmitData
Use this to configure the transmission of the guidance machine info message from your application....
 
static constexpr std::uint32_t GUIDANCE_MESSAGE_TX_INTERVAL_MS
How often guidance messages are sent, defined in ISO 11783-7.
 
@ Priority3
Priority highest - 3 (Control messages priority)
 
std::uint32_t get_parameter_group_number() const
Returns the PGN encoded in the identifier.
 
A class that represents a generic CAN message of arbitrary length.
 
std::uint32_t get_data_length() const
Returns the length of the data in the CAN message.
 
std::shared_ptr< ControlFunction > get_source_control_function() const
Gets the source control function that the message is from.
 
std::uint8_t get_uint8_at(const std::uint32_t index) const
Get a 8-bit unsigned byte from the buffer at a specific index. A 8-bit unsigned byte can hold a value...
 
std::uint16_t get_uint16_at(const std::uint32_t index, const ByteFormat format=ByteFormat::LittleEndian) const
Get a 16-bit unsigned integer from the buffer at a specific index. A 16-bit unsigned integer can hold...
 
CANIdentifier get_identifier() const
Returns the identifier of the message.
 
static CANNetworkManager CANNetwork
Static singleton of the one network manager. Use this to access stack functionality.
 
void add_any_control_function_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent)
Registers a callback for ANY control function sending the associated PGN.
 
bool send_can_message(std::uint32_t parameterGroupNumber, const std::uint8_t *dataBuffer, std::uint32_t dataLength, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction=nullptr, CANIdentifier::CANPriority priority=CANIdentifier::CANPriority::PriorityDefault6, TransmitCompleteCallback txCompleteCallback=nullptr, void *parentPointer=nullptr, DataChunkCallback frameChunkCallback=nullptr)
This is the main way to send a CAN message of any length.
 
void remove_any_control_function_parameter_group_number_callback(std::uint32_t parameterGroupNumber, CANLibCallback callback, void *parent)
This is how you remove a callback added with add_any_control_function_parameter_group_number_callback...
 
Defines an interface for sending and receiving ISOBUS guidance messages. These messages are used to s...
 
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
 
constexpr std::uint8_t CAN_DATA_LENGTH
The length of a classical CAN frame.