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

C: Get IMU v2 configuration #47

Closed
generalazure opened this issue May 29, 2017 · 5 comments
Closed

C: Get IMU v2 configuration #47

generalazure opened this issue May 29, 2017 · 5 comments

Comments

@generalazure
Copy link

Hello,
I can connect to and get various sensor data from my IMU v2 (with realistic values), but I run into trouble when I try to query the configuration. Specifically, calling imu_v2_get_sensor_configuration sets all the output values to 204 (which is invalid for all of them and suspiciously looks like uninitialized memory), then indicates success by returning 0.
I had a quick glance at the code, but cannot quite tell where these values are supposed to be copied: The single memcpy in ip_connection::device_send_request appears to only deal with the header (copies a chuck of size response_packet.header.length, which is always 8 bytes for me).

@photron
Copy link
Member

photron commented May 29, 2017

Are you sure that you're using the correct UID for your IMU Brick 2.0?

@generalazure
Copy link
Author

I am using the same UID that is shown in Brick Viewer and that works fine for getting sensor measurements. I've created a minimal example:

IPConnection ipcon;
ipcon_create(&ipcon);
IMUV2 imu;
imu_v2_create(&imu, "6QF9YH" , &ipcon);
int ret = ipcon_connect(&ipcon, "localhost", 4223);
uint8_t magRate, gyroRange, gyroBandwidth, accRange, accBandwidth;
ret = imu_v2_get_sensor_configuration(&imu, &magRate, &gyroRange, &gyroBandwidth, &accRange, &accBandwidth);
int8_t temp;
ret = imu_v2_get_temperature(&imu, &temp);

Executing the code above in VS2013 x64 debug mode gives me a correct temp (currently 31), but 204 for all config values. The return value of all 3 calls is 0.

@photron
Copy link
Member

photron commented May 30, 2017

I tested this with VS 2015 and it works for me.

Are you using the latest C/C++ bindings (2.1.15) and the latest IMU Brick 2.0 firmware (2.0.8)? If not, does ist make a difference if you update?

Could you test the following example with the modified ip_connection.c from this gist and show me its output?

https://gist.github.com/photron/fc3af20746305ad8ae46c4182e9f237f

#include <stdio.h>

#include "ip_connection.h"
#include "brick_imu_v2.h"

int main(void) {
	IPConnection ipcon;
	ipcon_create(&ipcon);
	IMUV2 imu;
	imu_v2_create(&imu, "6QF9YH" , &ipcon);
	int ret = ipcon_connect(&ipcon, "localhost", 4223);
	printf("A %d\n", ret);
	uint8_t magRate, gyroRange, gyroBandwidth, accRange, accBandwidth;
	ret = imu_v2_get_sensor_configuration(&imu, &magRate, &gyroRange, &gyroBandwidth, &accRange, &accBandwidth);
	printf("B %d %d %d %d %d %d\n", ret, magRate, gyroRange, gyroBandwidth, accRange, accBandwidth);
	int8_t temp;
	ret = imu_v2_get_temperature(&imu, &temp);
	printf("C %d %d\n", ret, temp);
	imu_v2_destroy(&imu);
	ipcon_destroy(&ipcon);
	return 0;
}

The modified IP connection will dump the raw requests and responses. The output should look similar to this.

A 0
S 8: 48 22 56 197 8 42 40 0 -> 0
R 13: 48 22 56 197 13 42 40 0 5 0 7 1 3 -> 0
B 0 5 0 7 1 3
S 8: 48 22 56 197 8 4 56 0 -> 0
R 9: 48 22 56 197 9 4 56 0 36 -> 0
C 0 36

@generalazure
Copy link
Author

Good call about the firmware version, updating from 2.0.4 to 2.0.8 solved the issue. Response packet length is 5 bytes more now and the contained values make sense. Guess I should run updates more often.
Anyway, thanks for the help :)

@photron
Copy link
Member

photron commented May 30, 2017

The imu_v2_get_sensor_configuration function was added in firmware version 2.0.5. Therefore, firmware 2.0.4 should respond with an error and the C/C++ bindings should return E_NOT_SUPPORTED (-10). But there was a bug in the firmware, that made the Brick not correctly report an error in this case. That's why imu_v2_get_sensor_configuration returned 0, while it should actually have returned E_NOT_SUPPORTED (-10). This bug was fixed a while ago.

Your problem was trying to call imu_v2_get_sensor_configuration with a firmware that does't have that function yet, but also has a bug that makes it report this incorrectly. So nothing to fix here actually.

@photron photron closed this as completed May 30, 2017
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

2 participants