Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the MicroInfinity CruizCore XG1300L gyroscope working #34

Open
LeeJenkins opened this issue Nov 30, 2017 · 9 comments
Open

Comments

@LeeJenkins
Copy link

I'm trying to use an XG1300L gyroscope attached to my EV3, but I'm not able to get it working in my C++ program. I'm looking for help getting it to connect. I assume I've just missed a simple step, but I cannot figure out where I've gone wrong.

I'm following the example code in the ev3dev-mapping code by bmegli. Specifically, I looked at how he used the gyro in the dead-reconing module. It doesn't look like he's doing anything beyond declaring the sensor.

32    const char *GYRO_PORT="i2c-legoev35:i2c1";
...
85    ev3dev::i2c_sensor gyro(GYRO_PORT, {"mi-xg1300l"});

Later the code checks gyro->connected() before sending a command. Easy, right? Well, maybe not. It looks like bmegli may have modified the i2c_sensor class to get it working.

I certainly haven't been able to get it to work. Here's my code:

void gyroTest() {
    std::cout << "make instance of migyro" << std::endl;
    ev3dev::i2c_sensor mnfinity_gyro( "i2c-legoev35:i2c1", {"mi-xg1300l"} );
    if( !mnfinity_gyro.connected() ) {
        std::cout << "migyro.connected(): FALSE" << std::endl;
        return;
    }
    std::cout << "migyro.connected(): TRUE" << std::endl;
    return;
}

When I run the program, it always prints FALSE. This doesn't look like rocket surgery, so I must be passing an incorrect argument value. But I cannot find any other example code and I don't know if I need to get bmegli's patch. Someone who has used this sensor will surely be able to point me in the right direction.

As a sanity check, I booted the EV3 with the LEGO firmware and then ran a sample program from the Microinfinity web site that uses the LEGO Mindstorms block-programming environment. The program was able to display readings from the sensor, so I know the hardware is good and attached properly.

Here's my ev3dev sysinfo:

robot@ev3dev:~$ ev3dev-sysinfo -m
<!-- Copy everything between these lines -->
**System info (from `ev3dev-sysinfo`)**
```
Image file:         ev3dev-jessie-ev3-generic-2017-09-14
Kernel version:     4.4.87-22-ev3dev-ev3
Board:              LEGO MINDSTORMS EV3 Programmable Brick
Revision:           0006
Brickman:           0.8.1
ev3devKit:          0.4.3
```
<!-- Copy everything between these lines -->
robot@ev3dev:~$
@ddemidov
Copy link
Owner

ddemidov commented Nov 30, 2017

Can you see the device in /sys/class/lego-sensor from command line? (ls /sys/class/lego-sensor). If this is the only connected sensor, it should be named sensor0. Can you check its address and driver_name attributes?

cat /sys/class/lego-sensor/sensor*/address
cat /sys/class/lego-sensor/sensor*/driver_name

@LeeJenkins
Copy link
Author

I unplugged all the other sensors so only the XG1300L was attached.

robot@ev3dev:~$ ls -ls /sys/class/lego-sensor/sensor*
ls: cannot access /sys/class/lego-sensor/sensor*: No such file or directory

Also, when I go to the Device Browser in Brickman there are no sensors listed.

Do I need to install support for this sensor?

@WasabiFan
Copy link
Collaborator

If this sensor isn't auto-detected you'll need to configure the port to tell it what driver to use. It looks like this one is an I2C-based sensor designed for the NXT so you'd probably use the nxt-i2c mode (I don't know if that's exactly right). I think we've previously discussed how to do that in C++.

@ddemidov
Copy link
Owner

ddemidov commented Dec 1, 2017

http://python-ev3dev.readthedocs.io/en/stable/other.html#lego-port

This links python docs, but should be helpful anyway.

@LeeJenkins
Copy link
Author

@WasabiFan I had the same thought. I used a lego_port device to set the mode like this:

ev3dev::lego_port in1 ( ev3dev::INPUT_1 );
in1.set_mode ( "nxt-i2c" );

I verified that the mode does actually change. And the port object reports that it is connected. But even so, when I create an i2c_sensor, it reports itself not connected.

According to the sensor docs, it looks like "nxt-i2c" is the correct mode. I also noticed that the footnotes for the sensor say it doesn't follow the LEGO guidelines for I2c registers and cannot be automatically detected. The docs go on to say that in order to register the i2c device you execute the following command:

echo mi-xg1300l 0x01 > /sys/class/lego-port/portN/set_device

But when I run the command (on ports in my case), bash reports an error:

-bash: echo: Write error: Operation not supported

So I'm still doing it wrong. Somehow.

@LeeJenkins
Copy link
Author

LeeJenkins commented Dec 1, 2017

@ddemidov I read through the port documentation and saw that it mentioned using set_device to specify the sensor type. So I tried this:

in1.set_set_device ( "mi-xg1300l" );

But when I call the function, it throws an exception with the same message (Operation not supported) that I saw when I tried to echo a string to the set_device file in /sys/class/lego_port. I don't know enough (basically zero) about the port interface in /sys to understand why I'm seeing that message.

@ddemidov
Copy link
Owner

ddemidov commented Dec 1, 2017

I am sorry, I have zero experience with non-standard sensors. May be @dlech could help.

@ddemidov
Copy link
Owner

ddemidov commented Dec 1, 2017

Did you give the sensor enough time after setting the mode and device?
This looks to be related: ev3dev/ev3dev#1000 (comment)

@LeeJenkins
Copy link
Author

@ddemidov and @WasabiFan Thanks to both of you for the support. I've reposted this issue to the main ev3dev forum because it seems to be a sensor issue and not a C++ issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants