Kart/serial link

(Difference between revisions)
Jump to: navigation, search
(Register Map)
(Registers)
(26 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{private}}
 
 
{{TOC right}}
 
{{TOC right}}
 
== Serial link protocol ==
 
== Serial link protocol ==
  
This section defines the serial link protocol used to communicate between the Kart and the SmartPhone. All data is spontaneous send and can not be polled.
+
This section defines the serial link protocol used to communicate between the Kart and the SmartPhone.
 +
All data is spontaneously sent.
  
 
=== Serial port===
 
=== Serial port===
Line 37: Line 37:
 
|-
 
|-
 
| 0
 
| 0
| INT16
+
| UINT16
 
| DC motor PWM period
 
| DC motor PWM period
 
|-
 
|-
 
| 1
 
| 1
| INT8
+
| INT5
| DC motor speed: -15 to 15 (Negative numbers = backwards)
+
| DC motor speed: -15 to 15 (negative numbers = backwards)
|-
+
| 1
+
| UINT16
+
| Desired Steering Angle
+
 
|-
 
|-
 
| 2
 
| 2
 
| UINT16
 
| UINT16
| stepper motor period (speed proportional to 1/period)
+
| Stepper motor period (speed proportional to 1/period)
 
|-
 
|-
 
| 3
 
| 3
 
| UINT16
 
| UINT16
| LEDs
+
| Desired steering angle (in motor steps, 0 = end switch)
 
|-
 
|-
 
| 4
 
| 4
| UINT16
+
| UINT5
| Hardware orientation
+
| End switch address
 
|-
 
|-
 
| 5
 
| 5
 +
| UINT5
 +
| [[Kart/serial_link#Hardware_control_register|Hardware control]]
 +
|-
 +
| 6
 +
| UINT4
 +
| LEDs
 +
|-
 +
| 7
 +
| UINT2
 +
| Sequence control register
 +
|-
 +
| 8
 +
| UINT16
 +
| Sequence operations register
 +
|-
 +
| 15
 
| UINT16
 
| UINT16
| Update interval [ms]
+
| Serial link update interval [ms]
 
|}
 
|}
  
=== Kart to SmartPhone ===
+
==== Hardware control register ====
 +
 
 +
The hardware control register allows to adapt the controls to the hardware of the car
 +
and to simulate events such as a stepper end switch.
  
 
{| cellpadding="4" cellspacing="0" border="1"
 
{| cellpadding="4" cellspacing="0" border="1"
! Address
+
! Bit
! Datatype
+
! Meaning
 
! Description
 
! Description
 
|-
 
|-
| 8
+
| 0
| UINT16
+
| Kart goes as DC motor
| Actual Steering Angle
+
| When '0', the kart goes backwards when the motor turns forwards
 
|-
 
|-
| 9
+
| 1
|UINT16
+
| Kart turns right (clockwise)
| ADC Value of the Battery Voltage Level
+
| When '1', kart turns to the right as stepper motor phases go from 1 to 4
 
|-
 
|-
| 10
+
| 2
|UINT1
+
| End sensor is on left side
| Stepper End = 1
+
| If '1', the angles are measured clockwise
 
|-
 
|-
 +
| 3
 +
| Stepper end
 +
| Emulates an end switch contact for the direction motor
 +
|-
 +
| 4
 +
| Restart
 +
| Puts following slaves back in startup mode: stepper motor<br />The DC motor is stopped as long as the signal is active
 +
|-
 +
| 5
 +
| Bluetooth connected
 +
| Indicates that the Bluetooth connection is established
 +
|}
 +
 +
The end sensor always defines position 0. Angles are always positive.
 +
 +
If bits 1 and 2 are different, the stepper motor phase sequence has to be inverted.
 +
 +
If the Bluetooth connection is lost, the DC motor has to be stopped.
 +
 +
==== Sequence control register ====
 +
 +
The sequence control register is used to load a new sequence from start of memory as well as to start and stop a sequence.
 +
 +
{| cellpadding="4" cellspacing="0" border="1"
 +
! Bit
 +
! Meaning
 +
! Description
 +
|-
 +
| 0
 +
| Reset sequence
 +
| sets the sequence RAM write and read addresses back to 0
 +
|-
 +
| 1
 +
| Run / stop
 +
| starts or stops a sequence
 +
|}
 +
 +
==== Sequence operations register ====
 +
 +
The sequence memory is made out of 16-bit controls and the sequence can range up to 2<sup>10</sup> operations.
 +
From the communication point of view, the sequence memory is seen as a FIFO&nbsp;:
 +
the sequence operations are pushed one after the other into the sequence register,
 +
starting at the first one of the list after the <code>reset sequence</code> bit
 +
has been set in the [[#Control register|control register]]
 +
 +
The sequence operations are split into 2&nbsp;parts: a 4-bit command and optional parameters.
 +
A sequence register has been defined in order to build loops:
 +
the <code>goto</code> operation is only carried out if the register is not zero.
 +
The register is initialised with all bits to&nbsp;'1'.
 +
 +
{| cellpadding="4" cellspacing="0" border="1"
 
|
 
|
|
+
! colspan = "2" | command
 +
! parameter
 +
| comment
 +
|-
 +
| Bits
 +
! colspan = "2" | 15 ÷ 12
 +
! 11 ÷ 0
 
|
 
|
 
|-
 
|-
| 16
+
| rowspan = "13" | || 0 || nop || ||
|UINT16
+
| Ambient Light 1
+
 
|-
 
|-
| 17
+
| 1 || set speed || speed || set the propulsion motor speed
|UINT16
+
| Ambient Light 2
+
 
|-
 
|-
| 18
+
| 2 || set angle || angle || set the direction motor angle
|UINT16
+
| Ambient Light 3
+
 
|-
 
|-
| 19
+
| 3 || drive LEDs || pattern || specify a given pattern for turning the LEDs on or off
|UINT16
+
| Ambient Light 4
+
 
|-
 
|-
| 20
+
| 4 || set LEDs || mask || set bits from '1's of mask
|UINT16
+
| Distance 1
+
 
|-
 
|-
| 21
+
| 5 || clear LEDs || mask || clear bits from '1's of mask
|UINT16
+
| Distance 2
+
 
|-
 
|-
| 22
+
| 6 || blink LEDs || period, mask || ''not implemented yet''
|UINT16
+
| Distance 3
+
 
|-
 
|-
| 23
+
| 8 || run distance || hall ticks || run until the Hall counter has augmented by at least a given tick number
|UINT16
+
| Distance 4
+
 
|-
 
|-
| 24
+
| 9 || run for || milliseconds || run for a specified time span
|UINT16
+
| Hall Sensor Counter 1
+
 
|-
 
|-
| 25
+
| A || run until || event || ''not implemented yet''
|UINT16
+
| Hall Sensor Counter 1
+
 
|-
 
|-
| 26
+
| D || modify register || operation, operand || bits 11÷10 : 00 = set, 10 = add, 11 = sub / bits 9÷0 : operand
|UINT16
+
| Hall Sensor Counter 3
+
 
|-
 
|-
| 27
+
| E || goto nz || address || jumps to the specified sequence step as long as the register is not zero
|UINT16
+
| Hall Sensor Counter 4
+
 
|-
 
|-
| 28
+
| F || end || || the sequence controller in the FPGA stops and the <code>running</code> status bit is cleared, announcing that the sequence is terminated
|UINT16
+
| Hall Sensor Counter 5
+
 
|}
 
|}
  
=== Hardware orientation ===
+
=== Kart to SmartPhone ===
  
 
{| cellpadding="4" cellspacing="0" border="1"
 
{| cellpadding="4" cellspacing="0" border="1"
! Bit
+
! Address
! Meaning
+
! Datatype
 
! Description
 
! Description
 
|-
 
|-
 
| 0
 
| 0
| Kart goes as DC motor
+
| UINT16
| When '0', the kart goes backwards when the motor turns forwards
+
| Hall speed count 1
 
|-
 
|-
 
| 1
 
| 1
| Kart turns right (clockwise)
+
| UINT16
| When '1', kart turns to the right as stepper motor phases go from 1 to 4
+
| Hall speed count 2
 
|-
 
|-
 
| 2
 
| 2
| End sensor is on left side
+
| UINT2
| If '1', the angles are measured clockwise.
+
| Steering status: bit 0 stepper end, bit 1 position reached
 +
|-
 +
| 3
 +
| UINT16
 +
| Actual Steering Angle
 +
|-
 +
| 4
 +
| UINT1
 +
| Stepper End from I/O board, bit 0
 +
|-
 +
| 5
 +
| UINT16
 +
| ADC Value of the Battery Voltage Level
 +
|-
 +
| 6
 +
| UINT16
 +
| Distance
 +
|-
 +
| 7
 +
| UINT16
 +
| Sequence status
 +
|-
 +
| 8
 +
| UINT16
 +
| Proximity 4
 +
|-
 +
| 9
 +
| UINT16
 +
| Proximity 3
 +
|-
 +
| 10
 +
| UINT16
 +
| Proximity 2
 +
|-
 +
| 11
 +
| UINT16
 +
| Proximity 1
 +
|-
 +
| 12
 +
| UINT16
 +
| Ambient Light 4
 +
|-
 +
| 13
 +
| UINT16
 +
| Ambient Light 3
 +
|-
 +
| 14
 +
| UINT16
 +
| Ambient Light 2
 +
|-
 +
| 15
 +
| UINT16
 +
| Ambient Light 1
 
|}
 
|}
  
The end sensor always defines position 0. Angles are always positive.
+
==== Sequence status register ====
  
If bits 1 and 2 are different, the stepper motor phase sequence has to be inverted.
+
The sequence status register tells what operation is currently active.
 +
 
 +
{| cellpadding="4" cellspacing="0" border="1"
 +
! Bit
 +
! Meaning
 +
! Description
 +
|-
 +
| 15 ÷ 12
 +
| Current command
 +
| indicates which command is currently being processed
 +
|-
 +
| 0
 +
| Running
 +
| indicates that a sequence is currently running
 +
|}
 +
 
 +
=== Kart I2C bus ===
 +
 
 +
The data on the kart's [[kart/I2C link|I2C bus]] reflects the one on the RS232 link.
 +
On the I2C, both data and addresses are 8-bit.
  
 
[[Category:Kart]]
 
[[Category:Kart]]

Revision as of 10:30, 26 August 2016

Contents

Serial link protocol

This section defines the serial link protocol used to communicate between the Kart and the SmartPhone. All data is spontaneously sent.

Serial port

Communication is done with:

  • 115200 baud
  • 8 bits
  • no parity
  • no handshake

Message Format

SoF (1 byte) Address (1 byte) Data (2 bytes) EoF (1 byte)
0x55 UINT8 UINT16/INT16 0xAA

Registers

SmartPhone to Kart

Address Datatype Description
0 UINT16 DC motor PWM period
1 INT5 DC motor speed: -15 to 15 (negative numbers = backwards)
2 UINT16 Stepper motor period (speed proportional to 1/period)
3 UINT16 Desired steering angle (in motor steps, 0 = end switch)
4 UINT5 End switch address
5 UINT5 Hardware control
6 UINT4 LEDs
7 UINT2 Sequence control register
8 UINT16 Sequence operations register
15 UINT16 Serial link update interval [ms]

Hardware control register

The hardware control register allows to adapt the controls to the hardware of the car and to simulate events such as a stepper end switch.

Bit Meaning Description
0 Kart goes as DC motor When '0', the kart goes backwards when the motor turns forwards
1 Kart turns right (clockwise) When '1', kart turns to the right as stepper motor phases go from 1 to 4
2 End sensor is on left side If '1', the angles are measured clockwise
3 Stepper end Emulates an end switch contact for the direction motor
4 Restart Puts following slaves back in startup mode: stepper motor
The DC motor is stopped as long as the signal is active
5 Bluetooth connected Indicates that the Bluetooth connection is established

The end sensor always defines position 0. Angles are always positive.

If bits 1 and 2 are different, the stepper motor phase sequence has to be inverted.

If the Bluetooth connection is lost, the DC motor has to be stopped.

Sequence control register

The sequence control register is used to load a new sequence from start of memory as well as to start and stop a sequence.

Bit Meaning Description
0 Reset sequence sets the sequence RAM write and read addresses back to 0
1 Run / stop starts or stops a sequence

Sequence operations register

The sequence memory is made out of 16-bit controls and the sequence can range up to 210 operations. From the communication point of view, the sequence memory is seen as a FIFO : the sequence operations are pushed one after the other into the sequence register, starting at the first one of the list after the reset sequence bit has been set in the control register

The sequence operations are split into 2 parts: a 4-bit command and optional parameters. A sequence register has been defined in order to build loops: the goto operation is only carried out if the register is not zero. The register is initialised with all bits to '1'.

command parameter comment
Bits 15 ÷ 12 11 ÷ 0
0 nop
1 set speed speed set the propulsion motor speed
2 set angle angle set the direction motor angle
3 drive LEDs pattern specify a given pattern for turning the LEDs on or off
4 set LEDs mask set bits from '1's of mask
5 clear LEDs mask clear bits from '1's of mask
6 blink LEDs period, mask not implemented yet
8 run distance hall ticks run until the Hall counter has augmented by at least a given tick number
9 run for milliseconds run for a specified time span
A run until event not implemented yet
D modify register operation, operand bits 11÷10 : 00 = set, 10 = add, 11 = sub / bits 9÷0 : operand
E goto nz address jumps to the specified sequence step as long as the register is not zero
F end the sequence controller in the FPGA stops and the running status bit is cleared, announcing that the sequence is terminated

Kart to SmartPhone

Address Datatype Description
0 UINT16 Hall speed count 1
1 UINT16 Hall speed count 2
2 UINT2 Steering status: bit 0 stepper end, bit 1 position reached
3 UINT16 Actual Steering Angle
4 UINT1 Stepper End from I/O board, bit 0
5 UINT16 ADC Value of the Battery Voltage Level
6 UINT16 Distance
7 UINT16 Sequence status
8 UINT16 Proximity 4
9 UINT16 Proximity 3
10 UINT16 Proximity 2
11 UINT16 Proximity 1
12 UINT16 Ambient Light 4
13 UINT16 Ambient Light 3
14 UINT16 Ambient Light 2
15 UINT16 Ambient Light 1

Sequence status register

The sequence status register tells what operation is currently active.

Bit Meaning Description
15 ÷ 12 Current command indicates which command is currently being processed
0 Running indicates that a sequence is currently running

Kart I2C bus

The data on the kart's I2C bus reflects the one on the RS232 link. On the I2C, both data and addresses are 8-bit.

Personal tools
Namespaces
Variants
Actions
Navigation
Modules / Projects
Browse
Toolbox