Skip to content

Search the documentation

Kit
Firmware

Compass

Smart Car

Tells which way the robot is facing, in degrees. It feels the Earth’s magnetic field, like a compass needle.

The Compass class is reached through this attribute of robot.

Can be None.

All the attributes of robot are in its table. Read Attributes that can be None to see when a part is None.

Which way the robot faces, in degrees from 0 up to 360; calibrate() first.

heading() -> float

Used in examples: Find north

Learns this robot’s compass: turn the robot slowly all the way round while it takes samples readings 50 ms apart, then it saves them.

calibrate(samples: int)

You can leave out samples.

Used in examples: Find north

True once the compass has been calibrated on this robot (the result is kept in compass_cal.json).

is_calibrated() -> bool

Used in examples: Find north

turn_to(heading, speed, tolerance, timeout_s, left, right)

Section titled “turn_to(heading, speed, tolerance, timeout_s, left, right)”

Turns the robot on the spot until it faces heading degrees, within tolerance degrees, at speed percent or more; gives up after timeout_s seconds.

turn_to(heading, speed: int, tolerance: int, timeout_s: int, left=None, right=None)

You can leave out speed, tolerance and timeout_s.

Used in examples: Find north

The shortest turn from heading current to heading target, in degrees from -180 to 180.

heading_error(target, current) -> float

Used in examples: Find north