PlayMaker Help & Tips > PlayMaker Help

External sensor interoperability possible?

(1/2) > >>

choi:
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:
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:
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 ();
      */
   }
}
-----------------------------------------------------------------------------------

jeanfabre:
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:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version