andycruce Geschrieben October 6, 2016 at 22:59 Geschrieben October 6, 2016 at 22:59 I am new to C# and can't get any of the examples to work. I have copied both the simple access example and the Quaternion Call Back example. Neither of these work for what appears to be different issues. The simple Quaternion access example generates a NotSupportedException when I execute imu.GetQuaternion(out w, out x, out y, out z) All the code is copied from the TinkerForge example, there are no compile errors. The ipcon is properly initialized and the imu object is properly initialized with the proper UID. I've check the IMU UID on using the BrickView app. I also tried the Quaternion Call Back example. This program also complies and shows no errors during execution. However, it appears the QuaternionCB function is never executed. A breakpoint there is never reached and there nothing is printed. The program gets to the Console.ReadLine statement and will exit if a return is entered. In both cases I am using System and Using Tinkerforge. I got the Tinkerforge dll from NuGet. Programs are being run under VS2015 as a console application. Any Suggestions? Zitieren
photron Geschrieben October 7, 2016 at 08:06 Geschrieben October 7, 2016 at 08:06 Whats the error message of the NotSupportedException? Are you using the IMU (1.0) examples with a IMU 2.0 or vice versa? Zitieren
andycruce Geschrieben October 7, 2016 at 15:44 Autor Geschrieben October 7, 2016 at 15:44 I am using an IMU2. The error message in the output window is: System.Notsupportedexception in Tinkerforge.dll The error message in the system routine that catches the exception is: Got Invalid Parameter for function ID8 Thanks for the quick reply - hope this helps. Zitieren
photron Geschrieben October 7, 2016 at 16:22 Geschrieben October 7, 2016 at 16:22 That's strange! This error makes no sense for function ID 8. Can you show your C# code? Zitieren
andycruce Geschrieben October 7, 2016 at 18:00 Autor Geschrieben October 7, 2016 at 18:00 Here is the code for the GetQuaternion function which returns the error: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tinkerforge; namespace TinkerForge_Test { class Program { private static string HOST = "localhost"; private static int PORT = 4223; private static string UID = "XXYYZZ"; // Change XXYYZZ to the UID of your IMU Brick 2.0 static void Main(string[] args) { IPConnection ipcon = new IPConnection(); // Create IP connection BrickIMUV2 imu = new BrickIMUV2("62feo2", ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current quaternion short w, x, y, z; // z = (short) 5.0; imu.GetQuaternion(out w, out x, out y, out z); string s = "w: {0:F02}, x: {1:F02}, y: {2:F02}, z: {3:F02}"; string f = String.Format(s, w / 16383.0, x / 16383.0, y / 16383.0, z / 16383.0); Console.WriteLine(f); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); } } } Here is the code for the Quaternion Call Back example which doesn't generate an error doesn't seem to access the Call Back functions since nothing is printed on the console. The console stays up until I enter a carriage return and the program seems to exit normally. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tinkerforge; namespace ConsoleApplication1 { class Example { private static string HOST = "localhost"; private static int PORT = 4223; private static string UID = "62feo2"; // Change XXYYZZ to the UID of your IMU Brick 2.0 // Callback function for quaternion callback static void QuaternionCB(BrickIMUV2 sender, short w, short x, short y, short z) { string s = "w: {0:F02}, x: {1:F02}, y: {2:F02}, z: {3:F02}"; string f = String.Format(s, w / 16383.0, x / 16383.0, y / 16383.0, z / 16383.0); Console.WriteLine(f); } static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickIMUV2 imu = new BrickIMUV2(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Register quaternion callback to function QuaternionCB imu.Quaternion += QuaternionCB; // Set period for quaternion callback to 0.1s (100ms) // Note: The quaternion callback is only called every 0.1 seconds // if the quaternion has changed since the last call! imu.SetQuaternionPeriod(100); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); } } } Hope this helps Andy Cruce Zitieren
photron Geschrieben October 10, 2016 at 08:44 Geschrieben October 10, 2016 at 08:44 This should just work. I tested it and it does. The only reason I can think of, is that you're using the wrong UID. Can you show a screenshot of the Brick Viewer Setup tab showing your IMU brick 2.0? Zitieren
andycruce Geschrieben October 10, 2016 at 12:08 Autor Geschrieben October 10, 2016 at 12:08 You were right. I was using the wrong UID. Was using the one for the master brick as opposed to the IMU. However, when I corrected this I received a timeout. Attached are two screen shots. One is the result of running the program with the correct UID - showing the timeout exception - and the other is a screen shot of the BrickView program. Does the program require a pause after the ipcon.Connect statement to allow the system to connect. I assumed the program wouldn't continue until the ipcom.Connect finished. Zitieren
photron Geschrieben October 10, 2016 at 12:24 Geschrieben October 10, 2016 at 12:24 6cPiac != 6CPiac Zitieren
andycruce Geschrieben October 10, 2016 at 16:38 Autor Geschrieben October 10, 2016 at 16:38 That did it. Sorry for the confusion. One other question. Do you know of anyone who has implemented a Kalman filter to combine IMU and GPS data? Andy Cruce Zitieren
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.