IS AIC

From LFS Manual
Jump to navigationJump to search

Introduction

The AI Control packet is used to control an AI car programmatically.

IS_AIC packet properties
Type Name Description
byte Size 4 + 4 * (number of inputs)
byte Type ISP_AIC
byte ReqI Optional - returned in any immediate response e.g. reply to CS_SEND_AI_INFO
byte PLID Unique ID of AI driver to control
AIInputVal Inputs [AIC_MAX_INPUTS]

Packet Details

Size

The size of the packet varies from 4 to 84 bytes depending on the number of Inputs.

Type

The packet type from the ISP_ enumeration, always ISP_AIC.

ReqI

ReqI is optional, it is returned in replies to this packet, e.g. when CS_SEND_AI_INFO is set.

PLID

The unique ID of the AI driver to control.

Inputs

The list of AIInputVal inputs to set on the AI car. Available inputs are the following:

// CS_MSX			 0 - steer: 1 hard left / 32768 centre / 65535 hard right
// CS_THROTTLE		 1 - 0 to 65535
// CS_BRAKE			 2 - 0 to 65535
// CS_CHUP			 3 - hold shift up lever
// CS_CHDN			 4 - hold shift down lever 
// CS_IGNITION		 5 - toggle
// CS_EXTRALIGHT	 6 - toggle
// CS_HEADLIGHTS	 7 - 1:off / 2:side / 3:low / 4:high
// CS_SIREN			 8 - hold siren - 1:fast / 2:slow
// CS_HORN			 9 - hold horn  - 1 to 5
// CS_FLASH			10 - hold flash - 1:on
// CS_CLUTCH		11 - 0 to 65535
// CS_HANDBRAKE		12 - 0 to 65535
// CS_INDICATORS	13 - 1: cancel / 2: left / 3: right / 4: hazard
// CS_GEAR			14 - for shifter (leave at 255 for sequential control)
// CS_LOOK			15 - 0: none / 4: left / 5: left+ / 6: right / 7: right+
// CS_PITSPEED		16 - toggle
// CS_TCDISABLE		17 - toggle
// CS_FOGREAR		18 - toggle
// CS_FOGFRONT		19 - toggle

Inputs marked 'hold' must be set back to zero after some time. This can be done either by use of the Time field or by sending a later packet with Value = 0. For instance, set Time to 10 when issuing a CS_CHUP to hold the shift up lever for 0.1 s.

Inputs marked 'toggle' accept the following values:

  • 1: toggle
  • 2: switch off
  • 3: switch on

There are also some special values available for Input:

#define CS_SEND_AI_INFO		240
#define CS_REPEAT_AI_INFO	241

#define CS_SET_HELP_FLAGS	253
#define CS_RESET_INPUTS		254
#define CS_STOP_CONTROL		255

CS_SEND_AI_INFO will result in an IS_AII packet being sent.

CS_REPEAT_AI_INFO starts or stops sending regular IS_AII packets, the interval is given in hundredths of a second.

CS_SET_HELP_FLAGS allows setting the following PIF_ player flags:

  • PIF_AUTOGEARS
  • PIF_HELP_B
  • PIF_AUTOCLUTCH

AI drivers default to PIF_AUTOCLUTCH only.

CS_RESET_INPUTS resets all inputs (zero everywhere except CS_MSX 32768 and CS_GEAR 255).

CS_STOP_CONTROL stops AI control, the AI driver stops the car entirely.

Notes

You cannot retrieve the state of the AI inputs, so you need to keep track of them if you need them. It is assumed that controls are updated very frequently, so that your latest commands are the current AI inputs.