playMaker

Author Topic: External sensor interoperability possible?  (Read 3354 times)

choi

  • Playmaker Newbie
  • *
  • Posts: 40
External sensor interoperability possible?
« on: October 22, 2012, 08:20:19 PM »
External sensor interoperability possible?
Example)
1 Computer connected to the sensor sends a signal. (Dll link)
2 Depending on the signal, the ball is moving.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: External sensor interoperability possible?
« Reply #1 on: October 23, 2012, 03:25:20 AM »
Hi,

 yes totally possible, you will simply need to create the custom actions to interface with your dll, and that's about it.

 If you need help on that, can you describe more about this dll? do you have it already working within Unity and regular scripts?


bye,

 Jean

choi

  • Playmaker Newbie
  • *
  • Posts: 40
Re: External sensor interoperability possible?
« Reply #2 on: October 23, 2012, 06:06:57 AM »
Hi
Code is made.
I want to control and playmaker.
-----------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;

[StructLayout(LayoutKind.Sequential)]
public class CR2_shotdata_t
{
   public int ballspeedX10;
   public int clubspeed_BX10;
   public int clubspeed_AX10;
   public int clubpathX10;
   public int clubfaceangleX10;
   public int sidespin;
   public int backspin;
   public int azimuthX10;
   public int inclineX10;
}

public class Sensor : MonoBehaviour {
   static BallInformation bm;
   
   static void Thread_Proc()
   {
      active();
   }
   
   
   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
   public delegate bool CallBackDelegate(int h, uint status, CR2_shotdata_t psd, int userparam);
   
   [DllImport("sensor4cs.dll", CallingConvention=CallingConvention.StdCall)]
   static extern void RegCallback(CallBackDelegate pCB);
   
   [DllImport("sensor4cs.dll")]
   public static extern void reStartShot();
   
   [DllImport("sensor4cs.dll")]
   static extern int init();
   
   [DllImport("sensor4cs.dll")]
   static extern void setTee(int use);

   [DllImport("sensor4cs.dll")]
   static extern void setClub(int useClub);
   
   [DllImport("sensor4cs.dll")]
   static extern void setWind();
   
   [DllImport("sensor4cs.dll")]
   static extern int active();
   
   [DllImport("sensor4cs.dll")]
   static extern void close();

   [DllImport("sensor4cs.dll")]
   static extern void deActivation();
   
   [DllImport("sensor4cs.dll")]
   static extern int getStatus();
   
   [DllImport("sensor4cs.dll")]
   static extern uint getSensorVersion();
   
   public static bool ShotCallFunc(int h, uint status, CR2_shotdata_t psd, int userparam) {
      ForceToBall ftb = GameObject.Find ("/Ball").GetComponent<ForceToBall>();
      bm.SetAngle(psd.inclineX10/10.0f);
      bm.SetBallSpeed(psd.ballspeedX10/10.0f);
      bm.SetHeadSpeed(psd.clubspeed_AX10/10.0f);
      ftb.sensorForce(psd.ballspeedX10, psd.inclineX10, psd.azimuthX10);
      return true;
   }
   
   //Thread sub_thread = new Thread(new ThreadStart(Thread_Proc));
   Thread sub_thread;
   CallBackDelegate callFunc;
   
   void Start() {
      bm = GameObject.Find ("/BallInformations").GetComponent<BallInformation>();
      sub_thread = new Thread(new ThreadStart(Thread_Proc));
      callFunc = new CallBackDelegate(ShotCallFunc);
      RegCallback(callFunc);

      sub_thread.Start ();
      
   }
   
   // Update is called once per frame
   void Update () {
      if(Input.GetKeyDown(KeyCode.Q)) {
         dispose();
         System.Diagnostics.Process.GetCurrentProcess().Kill();
      }      

   }
   
   void dispose()
   {
      if(sub_thread != null)
      {
         sub_thread.Abort();
         sub_thread = null;
      }
      deActivation();
      close();

      if(callFunc != null) {
         callFunc = null;   
      }
   
      //System.AppDomain.Unload(System.AppDomain.CurrentDomain);

      System.GC.Collect();
   }
   
   void OnDestroy() {
      dispose();   
   }
   
   void OnApplicationQuit() {
      dispose();
      if(Application.isEditor == false) {
         System.Diagnostics.Process.GetCurrentProcess().Kill();
      }
/*      deActivation();
      close ();
      sub_thread.Abort ();
      */
   }
}
-----------------------------------------------------------------------------------
« Last Edit: October 23, 2012, 06:09:50 AM by choi »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: External sensor interoperability possible?
« Reply #3 on: October 23, 2012, 07:38:46 AM »
ok, good , and what are you actually thinking of doing with PlayMaker if you have it already working? you will need most of this script and then simply either feed the feedback variables to give playmaker FSM for it to control the ball if you want playmaker to control the ball in the end.

--simply reference the playmaker fsm in your script using  public variable and inject data using the following technic:
http://hutonggames.com/playmakerforum/index.php?topic=1143.msg4800#msg4800

bye,

 Jean

choi

  • Playmaker Newbie
  • *
  • Posts: 40
Re: External sensor interoperability possible?
« Reply #4 on: October 23, 2012, 08:06:45 AM »
Thanks for your help.
I can only create the basic code.
So most of the script to create a playmaker.
Signal to move the ball comes.
1 Signal value
2 AddForce
3 Ball Shooting
It is not easy.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: External sensor interoperability possible?
« Reply #5 on: October 24, 2012, 04:04:44 AM »
Hi,

 get back to me in few days, and I will see what I can do.

bye,

 Jean

choi

  • Playmaker Newbie
  • *
  • Posts: 40
Re: External sensor interoperability possible?
« Reply #6 on: November 08, 2012, 08:51:03 AM »
Not, no ... code.
Help

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: External sensor interoperability possible?
« Reply #7 on: November 09, 2012, 01:38:51 AM »
Hi,

pm sent. Basically without the dll to test, it's not really possible to provide anything reliable and solid.

Bye,

 Jean