Machsupport Forum

Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: rcrabb on December 29, 2009, 05:09:51 PM

Title: Wiimote plugin
Post by: rcrabb on December 29, 2009, 05:09:51 PM
I'm working on a wiimote plugin for mach. Im using Ed's plugin wizard and the wiiuse lib. First I must say Ed did a fantastic job with this wizard and the videos gave my a huge leap forward with my learning curve. I have connected the wiimote to mach and displayed limited data in a dialog. Now Im stuck. The code below works great.

   WiiMoteStatus^   wiimotestatus = MG::wiimotestatus;
   WiiMoteConfig^   wiimoteconfig = MG::wiimoteconfig;
   wiimote** wiimotes;
   
   wiimotes =  wiiuse_init(wiimoteconfig->maxwiimotes);   // Send the max wiimotes to init (max of 1)
   

//--------------------------------------------------------------------
//   find and connect to the wiimotes
//--------------------------------------------------------------------

if (MG::wiimotestatus) // crashes without this line. learned the hard way
{
   if (!wiimotestatus->found)   // if we found one wiimote stop looking
   {
      wiimotestatus->found = wiiuse_find(wiimotes, wiimoteconfig->maxwiimotes, 10);   // We look for wiimotes (max of one, look for 10sec)

   }
   if (!wiimotestatus->connected)   //   if we are connected dont try to connect
   {
      wiimotestatus->connected = wiiuse_connect(wiimotes, wiimoteconfig->maxwiimotes);



Now my problem is in the next part-------------------------------------------------------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>


      wiiuse_poll(wiimotes, 1);

      wiiuse_motion_sensing(wiimotes[0], 1);

      wiimotestatus->roll = wiimotes[0]->orient.roll;

      
      if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_A))
      {
         wiimotestatus->debug = (true);
 



Everything compiles ok but mach crashes. Now wiiuse_poll is the function to poll the data from the wiiuse dll. it seems im having trouble getting to arrays of data returned.

I hope someone has an idea.
Title: Re: Wiimote plugin
Post by: ART on December 29, 2009, 09:14:32 PM
Hi:

>>wiimotestatus->connected = wiiuse_connect(wiimotes, wiimoteconfig->maxwiimotes);
Now my problem is in the next part-------------------------------------------------------------------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>
     wiiuse_poll(wiimotes, 1);
     wiiuse_motion_sensing(wiimotes[0], 1);
     wiimotestatus->roll = wiimotes[0]->orient.roll;
 
   ....

   Im not familiar with the wii motes calls, but it seems to me youd want to check to make sure the connection worked by checking
 is true or not before calling poll, and after calling connect..

Art


   
Title: Re: Wiimote plugin
Post by: rcrabb on December 29, 2009, 10:03:52 PM
Thanks Art.
 
Ill try that. What kills me is that I get that 9988 error and mach blows up. I have to reboot my computer everytime. And if I dont reboot after some time I get the blue screen. I will say im just learning c++ .NET and I have a long way to go. I was very exited when I got the wiimote connected and toggled one of the wiimote's leds. Now I hit a wall and need help. 
Title: Re: Wiimote plugin
Post by: ART on December 29, 2009, 10:51:49 PM
Hi:

 Yeah, Fatal errors tend to do that.. better then the old days of instant blue screen though. Take out a few lines to find what line exactly is causing it. Your code is assuming sucessfull completion by the look of it, if the calls dont properly send you a pointer to the remote though, youll end up querying a null pointer.. and that may be the cause of your trouble..

Art
Title: Re: Wiimote plugin
Post by: ART on December 29, 2009, 10:52:49 PM
If it were me, Id breakpoint on the poll line and check the contents of the wiimotes[0] variable..

Art
Title: Re: Wiimote plugin
Post by: rcrabb on December 29, 2009, 11:16:22 PM
This line crashed me.  wiimotes =  wiiuse_init(wiimoteconfig->maxwiimotes);

wiimoteconfig->maxwiimotes was the null. I added it and forgot that wiimoteconfig doesnt get gcnew till after postinit.

Now i need to figure out why I dont see any data after the poll. I cant get my code to run in debug so this will be a chalenge.
Title: Re: Wiimote plugin
Post by: rcrabb on December 30, 2009, 11:17:11 AM
I set a breakpoint at the poll line. There is no data in the wiimotes[0]. Now my code sets the first led on the wiimote after it connects so the wiiuse dll must be working. But I cant poll any data.
Title: Re: Wiimote plugin
Post by: rcrabb on December 30, 2009, 04:04:15 PM
Found my problem. I was sending an init call to the dll causing my variables to get wiped out. Now I have a new prob.

My array for the wiimote data is setup with this line.
wiimote** wiimotes;
wiimotes =  wiiuse_init(2);  <--------size of the array

But the data is gone after each pass through the code.

If i change it to this line.
static wiimote** wiimotes;
wiimotes =  wiiuse_init(2);  <--------size of the array

The data stays but the array is only one element. Now this is ok because I only plan to connect one wiimote but I would like to know the proper way to setup the arrays to work properly.
Title: Re: Wiimote plugin
Post by: ART on December 30, 2009, 05:27:26 PM
Hi :

 Seems that that would be specific to the wii dll as to function, but I suspect if more than one ispresent, that the dll will create the additional arrays..
Since its a pointer to a pointer its probably simply sending you the internal pointer to that data..

Art
Title: Re: Wiimote plugin
Post by: rcrabb on December 31, 2009, 12:09:42 AM
Thanks Art for your responses. I have all the accelerometer data and all buttons working. I also have the smoothing algorithm working. Of course all this is a part of the wiiuse dll and only needs to be called, for me it was a huge mountian to climb. A fun project.
Title: Re: Wiimote plugin
Post by: sunmix on January 09, 2010, 03:01:08 AM
i have a standard wiimote, how do you connect it to the PC, since the wimote is IR-based?
Title: Re: Wiimote plugin
Post by: rcrabb on January 09, 2010, 10:41:06 AM
Actually the wiimote uses bluetooth. The IR is used for tracking position on the TV screen. So you would need a USB bluetooth dongle if your PC doesnt have built in bluetooth.
Title: Re: Wiimote plugin
Post by: rcrabb on January 18, 2010, 07:44:17 PM
Im getting close the releasing the wiimote plugin. If there is anyone that would like to help me test it let me know. You will need a nintendo Wii controller ( wiimote ) and a bluetooth dongle or internal bluetooth in you pc.
Title: Re: Wiimote plugin
Post by: zafarsalam on January 21, 2010, 01:56:40 AM
I'd love to give it a try for testing. I have a 3 axis mill. I am using Xbox 360 plugin on it for job setup and quick facing jobs. Waiting for your plugin to get ready...

Zafar
Title: Re: Wiimote plugin
Post by: rcrabb on January 21, 2010, 10:00:20 AM
Zafar,

Do you have a Wiimote and bluetooth capabilties on your PC?
Title: Re: Wiimote plugin
Post by: zafarsalam on January 21, 2010, 11:50:16 PM
I'll have to bribe my kids to borrow their wiimote for testing :). I have usb bluetooth dongle with my pc too. I'll try to connect wiimote with my pc through this dongle today.

Zafar
Title: Re: Wiimote plugin
Post by: zafarsalam on January 22, 2010, 12:09:56 AM
An observation about bluetooth dongle and Mach. About a year ago I tried transferring gcode files to the machine pc through bluetooth dongle. Whenever I used bluesoeil software with the mach3 loaded it resulted in making my axes speeds extremely slow. And this thing could only be rectified by copying an older xml file to the current one. This didn't happen if I transferred the files after exiting Mach3. I haven't tried bluetooth on any of my machines since then. I wonder what was the cause then.

Zafar
Title: Re: Wiimote plugin
Post by: rcrabb on January 22, 2010, 03:54:47 PM
I'll put something together tonight for you to test. Im having some problems with the response time of the buttons when the accelerometer is turned on. So ill start by getting you a plugin with just buttons mapped to mach functions. If those work well on your system ill enable more features.
Title: Re: Wiimote plugin
Post by: sumoshay on May 14, 2010, 10:39:40 AM
This is exactly what I need for my project.  Is the wiimote plugin up and running?  If not, I would love to help you with the testing.