Compass
Smart CarTells which way the robot is facing, in degrees. It feels the Earth’s magnetic field, like a compass needle.
How you reach it
Section titled “How you reach it”The Compass class is reached through this attribute of robot.
robot.compass
Section titled “robot.compass”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.
Methods
Section titled “Methods”heading()
Section titled “heading()”Which way the robot faces, in degrees from 0 up to 360; calibrate() first.
heading() -> floatUsed in examples: Find north
calibrate(samples)
Section titled “calibrate(samples)”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
is_calibrated()
Section titled “is_calibrated()”True once the compass has been calibrated on this robot (the result is kept in compass_cal.json).
is_calibrated() -> boolUsed 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
heading_error(target, current)
Section titled “heading_error(target, current)”The shortest turn from heading current to heading target, in degrees from -180 to 180.
heading_error(target, current) -> floatUsed in examples: Find north