virantha / bricknil

Control LEGO Bluetooth Sensors and Motors with Python
https://virantha.github.io/bricknil
Apache License 2.0
142 stars 39 forks source link

ID of sensors inside Technic Plus Hub #18

Open ThinhNguyen168 opened 4 years ago

ThinhNguyen168 commented 4 years ago

Hello,

Thank you for this great project. I have tried your example technic_4x4.py which works well for me. Do you know the ID of the sensors inside the Technic Plus Hub (which also include an IMU)? I would like to get access to the orientation of the hub. Look forward to hearing from you.

BuongiornoTexas commented 4 years ago

I'm not at this point yet, so I'm guessing the constants in https://github.com/virantha/bricknil/blob/master/bricknil/const.py aren't what you are looking for? In that case, the constants at the bottom of https://github.com/nathankellenicki/node-poweredup/blob/master/src/hubs/technicmediumhub.ts may be what you need?

ThinhNguyen168 commented 4 years ago

Thank you very much. Now I can access to the voltage, current sensors and accelerometer of the hub. However the tilt sensor (port 99 according to https://github.com/nathankellenicki/node-poweredup/blob/master/src/hubs/technicmediumhub.ts) does not work. I don't know if the port 99 is incorrect or I don't have the right sensor id. Will continue investigating. Thank you again.

ThinhNguyen168 commented 4 years ago

For those who want to use the sensor of Technic Plus Hub, you can add the following lines of code at the end of file \bricknil\sensor\sensor.py:

class AccelerometerSensor(Peripheral): """ Access the internal accelerometer of the PowerUp+ hub

class GyroSensor(Peripheral): """ Access the internal gyroscope of the PowerUp+ hub

class TiltSensor(Peripheral): """ Access the internal tilt sensor in the Technic Plus hub

    - **sense_angle** - angles around Z, Y, X axes in degree (3x2 bytes).  Equal to 0 if hub is lying flat with button up and yaw angle is the same as starting.

    Examples::

        # Basic tilt sensor
        @attach(TiltSensor, name='tilt', capabilities=['sense_angle'])
"""
_sensor_id = 0x003B
capability = Enum("capability", {'sense_angle': 0})

datasets = { 
             capability.sense_angle: (3, 2),
            }

allowed_combo = [ ]