AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
isobus_guidance_interface.hpp
Go to the documentation of this file.
1//================================================================================================
21//================================================================================================
22#ifndef ISOBUS_GUIDANCE_INTERFACE_HPP
23#define ISOBUS_GUIDANCE_INTERFACE_HPP
24
26#include "isobus/utility/event_dispatcher.hpp"
27#include "isobus/utility/processing_flags.hpp"
28
29#include <memory>
30#include <vector>
31
32namespace isobus
33{
36 {
37 public:
43 AgriculturalGuidanceInterface(std::shared_ptr<InternalControlFunction> source,
44 std::shared_ptr<ControlFunction> destination,
45 bool enableSendingSystemCommandPeriodically = false,
46 bool enableSendingMachineInfoPeriodically = false);
47
50
58 {
59 public:
62 enum class CurvatureCommandStatus : std::uint8_t
63 {
65 IntendedToSteer = 1,
66 Error = 2,
67 NotAvailable = 3
68 };
69
72 explicit GuidanceSystemCommand(std::shared_ptr<ControlFunction> sender);
73
79 bool set_status(CurvatureCommandStatus newStatus);
80
84
96 bool set_curvature(float curvature);
97
100 float get_curvature() const;
101
104 std::shared_ptr<ControlFunction> get_sender_control_function() const;
105
108 void set_timestamp_ms(std::uint32_t timestamp);
109
112 std::uint32_t get_timestamp_ms() const;
113
114 private:
115 std::shared_ptr<ControlFunction> const controlFunction;
116 float commandedCurvature = 0.0f;
117 std::uint32_t timestamp_ms = 0;
118 CurvatureCommandStatus commandedStatus = CurvatureCommandStatus::NotAvailable;
119 };
120
123 {
124 public:
128 enum class MechanicalSystemLockout : std::uint8_t
129 {
130 NotActive = 0,
131 Active = 1,
132 Error = 2,
133 NotAvailable = 3
134 };
135
138 enum class RequestResetCommandStatus : std::uint8_t
139 {
140 ResetNotRequired = 0,
141 ResetRequired = 1,
142 Error = 2,
143 NotAvailable = 3
144 };
145
147 enum class GenericSAEbs02SlotValue : std::uint8_t
148 {
149 DisabledOffPassive = 0,
150 EnabledOnActive = 1,
151 ErrorIndication = 2,
152 NotAvailableTakeNoAction = 3
153 };
154
157 enum class GuidanceLimitStatus : std::uint8_t
158 {
159 NotLimited = 0,
161 LimitedHigh = 2,
162 LimitedLow = 3,
163 Reserved_1 = 4,
164 Reserved_2 = 5,
166 NotAvailable = 7
167 };
168
172 {
173 NoReasonAllClear = 0,
174 RequiredLevelOfOperatorPresenceAwarenessNotDetected = 1,
175 ImplementReleasedControlOfFunction = 2,
176 OperatorOverrideOfFunction = 3,
177 OperatorControlNotInValidPosition = 4,
178 RemoteCommandTimeout = 5,
179 RemoteCommandOutOfRangeInvalid = 6,
180 FunctionNotCalibrated = 7,
181 OperatorControlFault = 8,
182 FunctionFault = 9,
183 HydraulicOilLevelTooLow = 20,
184 HydraulicOilTemperatureTooLow = 21,
186 VehicleSpeedTooLow = 23,
187 VehicleSpeedTooHigh = 24,
188 AlternateGuidanceSystemActive = 25,
189 ControlUnitInDiagnosticMode = 26,
190 Error = 62,
191 NotAvailable = 63
192 };
193
196 explicit GuidanceMachineInfo(std::shared_ptr<ControlFunction> sender);
197
201 bool set_estimated_curvature(float curvature);
202
205 float get_estimated_curvature() const;
206
211
215
220
224
229
233
240
246
254
261
267 bool set_guidance_system_command_exit_reason_code(std::uint8_t exitCode);
268
274
279
283
286 std::shared_ptr<ControlFunction> get_sender_control_function() const;
287
290 void set_timestamp_ms(std::uint32_t timestamp);
291
294 std::uint32_t get_timestamp_ms() const;
295
296 private:
297 std::shared_ptr<ControlFunction> const controlFunction;
298 float estimatedCurvature = 0.0f;
299 std::uint32_t timestamp_ms = 0;
300 MechanicalSystemLockout mechanicalSystemLockoutState = MechanicalSystemLockout::NotAvailable;
301 GenericSAEbs02SlotValue guidanceSteeringSystemReadinessState = GenericSAEbs02SlotValue::NotAvailableTakeNoAction;
302 GenericSAEbs02SlotValue guidanceSteeringInputPositionStatus = GenericSAEbs02SlotValue::NotAvailableTakeNoAction;
303 GenericSAEbs02SlotValue guidanceSystemRemoteEngageSwitchStatus = GenericSAEbs02SlotValue::NotAvailableTakeNoAction;
304 RequestResetCommandStatus requestResetCommandStatus = RequestResetCommandStatus::NotAvailable;
307 };
308
311 void initialize();
312
315 bool get_initialized() const;
316
320
324
328
332
339 std::shared_ptr<GuidanceMachineInfo> get_received_guidance_machine_info(std::size_t index);
340
347 std::shared_ptr<GuidanceSystemCommand> get_received_guidance_system_command(std::size_t index);
348
351 EventDispatcher<const std::shared_ptr<GuidanceMachineInfo>, bool> &get_guidance_machine_info_event_publisher();
352
355 EventDispatcher<const std::shared_ptr<GuidanceSystemCommand>, bool> &get_guidance_system_command_event_publisher();
356
359 void update();
360
361 protected:
363 enum class TransmitFlags : std::uint32_t
364 {
367
369 };
370
374 static void process_flags(std::uint32_t flag, void *parentPointer);
375
379 static void process_rx_message(const CANMessage &message, void *parentPointer);
380
381 static constexpr std::uint32_t GUIDANCE_MESSAGE_TX_INTERVAL_MS = 100;
382 static constexpr std::uint32_t GUIDANCE_MESSAGE_TIMEOUT_MS = 150;
383 static constexpr float CURVATURE_COMMAND_OFFSET_INVERSE_KM = 8032.0f;
384 static constexpr float CURVATURE_COMMAND_MAX_INVERSE_KM = 8031.75f;
385 static constexpr float CURVATURE_COMMAND_RESOLUTION_PER_BIT = 0.25f;
386 static constexpr std::uint16_t ZERO_CURVATURE_INVERSE_KM = 32128;
387
390 bool send_guidance_machine_info() const;
391
394 bool send_guidance_system_command() const;
395
396 ProcessingFlags txFlags;
397 EventDispatcher<const std::shared_ptr<GuidanceMachineInfo>, bool> guidanceMachineInfoEventPublisher;
398 EventDispatcher<const std::shared_ptr<GuidanceSystemCommand>, bool> guidanceSystemCommandEventPublisher;
399 std::shared_ptr<ControlFunction> destinationControlFunction;
400 std::vector<std::shared_ptr<GuidanceMachineInfo>> receivedGuidanceMachineInfoMessages;
401 std::vector<std::shared_ptr<GuidanceSystemCommand>> receivedGuidanceSystemCommandMessages;
404 bool initialized = false;
405 };
406} // namespace isobus
407
408#endif // ISOBUS_GUIDANCE_HPP
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
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 ...
MechanicalSystemLockout mechanicalSystemLockoutState
The reported state of the mechanical system lockout switch (SPN 5243)
GenericSAEbs02SlotValue
A typical, generic 2 bit value in J1939 with no superseding definition in ISO 11783.
float estimatedCurvature
Curvature in km^-1 (inverse kilometers). Range is -8032 to 8031.75 km-1 (SPN 5238)
bool set_mechanical_system_lockout_state(MechanicalSystemLockout state)
Sets the mechanical system lockout state.
std::shared_ptr< ControlFunction > const controlFunction
The CF that is sending the message.
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.
std::uint8_t guidanceSystemCommandExitReasonCode
The exit code for guidance, stored as a u8 to preserve manufacturer specific values (SPN 5725)
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 guidanceSystemRemoteEngageSwitchStatus
The reported state of the remote engage switch (SPN 9726)
RequestResetCommandStatus requestResetCommandStatus
The reported state of the request reset command (SPN 5240)
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.
GenericSAEbs02SlotValue guidanceSteeringSystemReadinessState
The reported state of the steering system's readiness to steer (SPN 5242)
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...
GuidanceSystemCommandExitReasonCode
This parameter is used to indicate why the guidance system cannot currently accept remote commands or...
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.
GenericSAEbs02SlotValue guidanceSteeringInputPositionStatus
The reported state of the steering input position. (SPN 5241)
GuidanceMachineInfo(std::shared_ptr< ControlFunction > sender)
Constructor for a GuidanceMachineInfo.
GuidanceLimitStatus guidanceLimitStatus
The steering system's present limit status associated with guidance commands that are persistent (SPN...
bool set_guidance_steering_input_position_status(GenericSAEbs02SlotValue state)
Sets the guidance steering input position state.
std::uint32_t timestamp_ms
A timestamp for when the message was released in milliseconds.
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.
float commandedCurvature
The commanded curvature in km^-1 (inverse kilometers)
bool set_status(CurvatureCommandStatus newStatus)
Sets the curvature command status that will be encoded into the CAN message. This parameter indicates...
std::shared_ptr< ControlFunction > const controlFunction
The CF that is sending the message.
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.
CurvatureCommandStatus commandedStatus
The current status for the command.
void set_timestamp_ms(std::uint32_t timestamp)
Sets the timestamp for when the message was received or sent.
std::uint32_t timestamp_ms
A timestamp for when the message was released in milliseconds.
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.
@ NumberOfFlags
The number of flags in this enumeration.
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.
static constexpr std::uint32_t GUIDANCE_MESSAGE_TIMEOUT_MS
Amount of time before a guidance message is stale. We currently tolerate 50ms of delay.
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.
A class that represents a generic CAN message of arbitrary length.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...