Skip to content

Make the special sensor class for the Infrared Sensor include IR-SEEK #302

Closed

Description

@fisherds
  • ev3dev version: 4.4.24-16-ev3dev-ev3
  • **ev3dev-lang-python version:**0.8.0

If you look at the special sensor classes for the Color Sensor and the Infrared Sensor you'll see the Color Sensor has a very robust special sensor class:
http://python-ev3dev.readthedocs.io/en/latest/sensors.html#special-sensor-classes

However the Infrared Sensor has only the one property: proximity. There is no support for the IR-SEEK mode within the special sensor class. You can of course use the sensor values directly if you read the sensor page:
http://www.ev3dev.org/docs/sensors/lego-ev3-infrared-sensor/

Your code looks like this, which isn't terrible.

        ir_sensor = ev3.InfraredSensor()
        ir_sensor.mode = "IR-SEEK"
        current_distance_channel1 = ir_sensor.value(0)
        current_heading_channel1 = ir_sensor.value(1)

Two issues:

  1. This approach is less elegant than first class properties / methods on the special sensor class. It makes IR-SEEK harder for new people to discover and makes the code feel more manual.
    Maybe we could add a method to call

         current_distance_channel1 = ir_sensor.beacon_distance(1)
         current_heading_channel1 = ir_sensor.beacon_heading(1)
    

or a bunch of properties (8 properties):

        current_distance_channel1 = ir_sensor.beacon_distance_ch1
        current_heading_channel1 = ir_sensor.beacon_heading_ch1
  1. This other problem I've noticed with the manual approach is that it's a bit buggy. It has errors sometimes when there is difficulty communicating with the sensor. If fires errors often enough that I've started wrapping calls in try: expect: blocks just in case (can happen when setting the mode too). If you run enough tests you'll see an error thrown too. I'm guessing there is a bit of protection built in with things like .proximity because I never see errors with them. So I'd like the elegance of adding IR-SEEK and the protection from errors that seems to happen with .proximity. :)

Yet again happy to let others drive, just putting in the feature request.

Activity

  1. ddemidov commented on Feb 13, 2017

    @ddemidov
    Member

    We have a helper class for working with remote control (unimaginatively named "RemoteControl"). It takes the RC channel number to work with upon construction. So may be it would be more natural to add the beacon methods to this class instead of the InfraredSensor. Or even create new class (IRBeacon?) for this.

  2. added this to the 0.8.2 milestone on Feb 13, 2017
  3. fisherds commented on Feb 13, 2017

    @fisherds
    Author

    Yeah there is no clear cut answer to where it fits best. I see your point that it uses both the IR sensor and remote, but I'll say I don't think we should touch RemoteControl. The IR-REMOTE mode is all digital and pretty different for users. I think users see RemoteControl like Button and adding in an analog sensor would be confusing (personally). I'm flexible if you feel otherwise. So personally I think the best options are:

    • Add it to InfraredSensor (lumps together IR-PROX and IR-SEEK modes)
    • Create a new special sensor class, called perhaps IRBeacon just for IR-SEEK mode

    I think my vote is to add it to the existing InfraredSensor class. Just feels more consistent with the ColorSensor auto mode stuff. I'm happy InfraredSensor and RemoteControl are separate as IR-REMOTE mode is pretty different, but I think the IR-SEEK and IR-PROX modes are close enough that we can lump them together, much like ColorSensor lumps things together. Fewer classes keeps things simpler. Just my two cents on what I think is easiest for users. Obviously we could go the RemoteControl route or IRBeacon route if you prefer.

  4. added a commit that references this issue on Feb 27, 2017
  5. added a commit that references this issue on Mar 23, 2017
  6. ddemidov commented on Mar 23, 2017

    @ddemidov
    Member

    Resolved by #311

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions