Skip to content

How to Get Value of 'TILT-ANGLE' in Gyro Sensor ? #616

Closed

Description

@deopark

4.14.96-ev3dev-2.3.2-ev3

ii python3-ev3dev 1.2.0 all Python language bindings for ev3dev
ii python3-ev3dev2 2.0.0~beta3 all Python language bindings for ev3dev

Hello!
I'm Testing to Get Value from 'TILT-ANGLE' mode of Gyro Sensor.
But The Following Error Occurs :
('TILT-RATE' Mode Is No Problem And Date Code of Sensor Is 'N6')

-Source Code-

#!/usr/bin/env python3
from ev3dev2.sensor import INPUT_1
from ev3dev2.sensor.lego import GyroSensor
from time import sleep
import sys

gy = GyroSensor(INPUT_1)
sleep(0.5)
while True:
    print(gy.tilt_angle, file=sys.stderr)
    #print(gy.tilt_rate, file=sys.stderr)
    sleep(0.5)

-Error code-

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 261, in _set_attribute
    attribute.write(value)
OSError: [Errno 22] Invalid argument

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/robot/start/01_gyro.py", line 16, in <module>
    print(int(gy.tilt_angle), file=sys.stderr)
  File "/usr/lib/python3/dist-packages/ev3dev2/sensor/lego.py", line 617, in tilt_angle
    self._ensure_mode(self.MODE_TILT_ANG)
  File "/usr/lib/python3/dist-packages/ev3dev2/sensor/__init__.py", line 280, in _ensure_mode
    self.mode = mode
  File "/usr/lib/python3/dist-packages/ev3dev2/sensor/__init__.py", line 182, in mode
    self._mode = self.set_attr_string(self._mode, 'mode', value)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 321, in set_attr_string
    return self._set_attribute(attribute, name, value)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 264, in _set_attribute
    self._raise_friendly_access_error(ex, name)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 281, in _raise_friendly_access_error
    chain_exception(ValueError("One or more arguments were out of range or invalid"), driver_error)
  File "/usr/lib/python3/dist-packages/ev3dev2/__init__.py", line 38, in chain_exception
    raise exception from cause
ValueError: One or more arguments were out of range or invalid
----------
Exited with error code 1.

Can Someone Fix This Problem by Modifying the Code?
Thank You !

Activity

  1. dlech commented on Apr 11, 2019

    @dlech
    Member

    What is the date stamp on your gyro sensor? (should be something like 25N5)

    The tilt mode is a hidden feature that is only available on some sensors.

  2. deopark commented on Apr 12, 2019

    @deopark
    Author

    Date Stamp of My Seneor Is '25N6', and the Following Code Works Well. (It Reads Value of tilt_rate Well)

    gy = GyroSensor(INPUT_1)
    while True:
        #print(gy.tilt_angle, file=sys.stderr)
        print(gy.tilt_rate, file=sys.stderr)
        sleep(0.5)
    

    As a Result, Except Value of tilt_angle(), It Can Get Value of All 'property' method(in GyroSensor class) including 'tilt_rate(self)'

    Is That Possible?

  3. dlech commented on Apr 12, 2019

    @dlech
    Member

    Maybe there is a typo in the mode name. What is the output of...

    print(gy.modes, file=sys.stderr)
  4. deopark commented on Apr 13, 2019

    @deopark
    Author

    Thank You for Your Reply.
    Your Advice Was Right.

    gy.modes
    ['GYRO-ANG', 'GYRO-RATE', 'GYRO-FAS', 'GYRO-G&A', 'GYRO-CAL', 'TILT-RATE', 'TILT-ANG']

    Mode Name is 'TILT-ANG'.

    But It was defined In GyroSensor class like Below.

    MODE_TILT_ANG = 'TILT-ANGLE'
    MODE_TILT_RATE = 'TILT-RATE'
    `

    so, I Could Get a Value of 'Tilt_angle' by Modifying my Code like Below.

    gy._ensure_mode('TILT-ANG')
    while True:
        
        print(gy.value(0), file=sys.stderr)
        #print(gy.tilt_angle, file=sys.stderr)
        #print(gy.tilt_rate, file=sys.stderr)
        sleep(0.5)
    

    Nevertheless, How Can I Modify the GyroSensor class Variable ?

  5. dlech commented on Apr 13, 2019

    @dlech
    Member

    At the beginning of your program (after the import statements), you can put...

    GyroSensor.MODE_TILT_ANG = 'TILT-ANG'
  6. added a commit that references this issue on Apr 13, 2019
    7e554ba
  7. added a commit that references this issue on Apr 13, 2019
    e41fca4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions