Γύρος#

Εισαγωγή#

Ο γυροσκοπικός αισθητήρας είναι ένας αισθητήρας κίνησης που ανιχνεύει την περιστροφή γύρω από έναν μόνο άξονα. Μπορεί να μετρήσει πόσο έχει στρίψει το ρομπότ, επιτρέποντάς του να παρακολουθεί τον προσανατολισμό και την κατεύθυνση.

This page uses drivetrain_gyro as the example Gyro Sensor name. Replace it with your own configured name as needed.

Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:

Ενέργειες — Βαθμονόμηση ή προσαρμογή της κατεύθυνσης και της περιστροφής του γυροσκοπικού αισθητήρα.

  • calibrate — Calibrates the Gyro Sensor for stable heading tracking.

  • set_heading — Sets the Gyro Sensor’s heading to a specified value.

  • set_rotation — Sets the Gyro Sensor’s rotation value.

  • reset_heading — Sets the heading of the Gyro Sensor to 0.

  • reset_rotation — Sets the rotation of the Gyro Sensor to 0.

Λήπτες — Διαβάστε την κατεύθυνση, την περιστροφή και την κατάσταση του γυροσκοπικού αισθητήρα.

  • heading — Returns the current heading.

  • rotation — Returns the cumulative rotation.

  • rate — Returns the angular velocity around the x, y, or z axis.

  • is_calibrating — Returns whether or not the Gyro Sensor is calibrating.

  • installed — Returns whether or not a Gyro Sensor is connected to the Brain.

Επανάκληση — Εκτέλεση κώδικα όταν ο γυροσκοπικός αισθητήρας ανιχνεύσει κίνηση ή αλλαγή.

  • changed — Registers a function to call when the Gyro Sensor detects change.

Κατασκευαστές — Μη αυτόματη αρχικοποίηση και διαμόρφωση ενός γυροσκοπικού αισθητήρα.

  • Gyro — Creates a Gyro Sensor.

Ενέργειες#

calibrate#

calibrate calibrates the Gyro Sensor. All subsequent lines will wait for the calibration to complete before executing. Calibration is an internal procedure that measures and compensates for sensor noise and drift over a specified period. During this time, the Gyro Sensor must remain completely still (i.e., on a stable surface without any external movement). Movement during calibration will produce inaccurate results.

Usage:
calibrate()

Παράμετρος

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Start Gyro Sensor calibration
drivetrain_gyro.calibrate()
# Print after calibration
while drivetrain_gyro.is_calibrating():
    wait(0.1, SECONDS)
brain.screen.print("Done!")

set_heading#

set_heading sets the heading of the Gyro Sensor to a specific value.

Usage:
set_heading(value, units)

Παράμετροι

Περιγραφή

αξία

Η τιμή επικεφαλίδας που θα οριστεί.

μονάδες

Optional. The unit used to represent the new heading:

  • DEGREES (default)
  • TURNS
# Turn the robot around
drivetrain_gyro.set_heading(180)
drivetrain.turn_to_heading(0)

set_rotation#

set_rotation sets the rotation of the Gyro Sensor to a specific value.

Usage:
set_rotation(value, units)

Παράμετροι

Περιγραφή

value

Η τιμή επικεφαλίδας που θα οριστεί.

units

Optional. The unit used to represent the new rotation value:

  • DEGREES (default)
  • TURNS
# Turn the robot around
drivetrain_gyro.set_rotation(-180)
drivetrain.turn_to_rotation(0)

reset_heading#

reset_heading resets the heading of the Gyro Sensor to 0.

Usage:
reset_heading()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Turn the robot before and after resetting the heading
drivetrain.turn_to_heading(90, DEGREES)
wait(0.5,SECONDS)
drivetrain_gyro.reset_heading()
drivetrain.turn_to_heading(90, DEGREES)

reset_rotation#

reset_rotation resets the rotation of the Gyro Sensor to 0.

Usage:
reset_rotation()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Turn the robot before and after resetting the rotation
drivetrain.turn_to_rotation(-90, DEGREES)
wait(0.5,SECONDS)
drivetrain_gyro.reset_rotation()
drivetrain.turn_to_rotation(-90, DEGREES)

Αποκτητές#

heading#

heading returns the current heading of the Gyro Sensor.

Usage:
heading(units)

Παράμετροι

Περιγραφή

units

Optional. The unit used to represent the heading:

  • DEGREES (default)
  • TURNS
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(drivetrain_gyro.heading())

rotation#

rotation returns the current rotation of the Gyro Sensor.

Usage:
rotation(units)

Παράμετροι

Περιγραφή

units

Optional. The unit used to represent the rotation:

  • DEGREES (default)
  • TURNS
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print(drivetrain_gyro.rotation())

rate#

rate returns the current rate of change of the Gyro Sensor’s rotation in specified units.

Usage:
rate(units)

Παράμετροι

Περιγραφή

units

Optional. The unit used to represent the gyro rate:

  • DPS (default)
  • RPM
  • PERCENT
# Display the rate of change of 
# rotation while turning
drivetrain.turn(RIGHT)
wait(1, SECONDS)
brain.screen.print(drivetrain_gyro.rate())
drivetrain.stop()

is_calibrating#

is_calibrating checks if the Gyro Sensor is currently calibrating.

  • True — The Gyro Sensor is calibrating.

  • False — The Gyro Sensor is not calibrating.

Usage:
is_calibrating()

Παράμετρος

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Start Gyro Sensor calibration.
drivetrain_gyro.calibrate()
# Print after calibration
while drivetrain_gyro.is_calibrating():
    wait(0.1, SECONDS)
brain.screen.print("Done!")

installed#

installed returns a Boolean indicating whether the Gyro Sensor is connected to the Brain.

  • True — The Gyro Sensor is connected to the Brain.

  • False — The Gyro Sensor is not connected to the Brain.

Usage:
installed()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display a message if the Gyro Sensor is
# installed.
if drivetrain_gyro.installed():
    brain.screen.print("Installed!")

Επανάκληση#

changed#

changed registers a callback function for when the Gyro Sensor’s heading changes.

Usage:
changed(callback, arg)

Παράμετροι

Περιγραφή

callback

Η συνάρτηση επανάκλησης που θα κληθεί όταν αλλάξει η επικεφαλίδα του γυροσκοπικού αισθητήρα.

arg

Προαιρετικό. Μια πλειάδα ορισμάτων που θα διαβιβαστεί στη συνάρτηση επανάκλησης.

def gyro_changed():
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Heading: ")
    brain.screen.print(drivetrain_gyro.heading()) 
# Display the heading when the gyro detects a change
drivetrain.turn_for(RIGHT, 90, DEGREES, wait=False)
drivetrain_gyro.changed(gyro_changed)

Κατασκευαστές#

Constructors are used to manually create Gyro objects, which are necessary for configuring a Gyro Sensor outside of VEXcode.

Gyro#

Gyro creates a Gyro Sensor.

Usage:
Gyro(smartport)

Παράμετρος

Περιγραφή

smartport

Η Έξυπνη Θύρα στην οποία είναι συνδεδεμένος ο Γυροσκοπικός Αισθητήρας, γραμμένη ως PORTx όπου x είναι ο αριθμός της θύρας.

# Create the Brain
brain = Brain()
# When constructing Gyro Sensor "drivetrain_gyro" with a 
# SmartDrive "drivetrain"
drivetrain_gyro = Gyro(Ports.PORT1)
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, drivetrain_gyro, 200)

drivetrain_gyro.set_heading(180)
drivetrain.turn_to_heading(0)