Creating Your Own Module for The KAI

Anupama Nair
Sep 29 · 2 min read

If you’ve jumped here from the blog that introduces you to the Kai SDK, then you're halfway to creating your first module for the Kai. If you haven’t given it a read, you may want to take a look at that blog first. Here’s the link.

Now that you’re here, let’s get you started. This blog contains a starter module that we have created for you. You can choose to start with this module just to try things out.

This module is a simple example where gestures correspond to actions taken on your computer. The Kai sends across multiple types of data on a subscription basis. Modules that are to integrate with the SDK must explicitly mention the capabilities it wants to receive. Therefore, by “subscribing” to specific Kai data, you are choosing the information that you want to receive from the Kai as and when events occur. This data could be anything from Gesture Data to Gyroscope, Accelerometer, Magnetometer or PYR data.

For the extent of this example, we’re creating a module that plays various sound clips when gestures are performed. Therefore, the data we will be subscribing to is GestureData.

You can start off by picking Visual Studio or JetBrains Rider.

Here are the steps to follow.

  • Create a new c# project.
  • Add a new New Nuget Dependency ( kai.WebSocketModule )
  • In your main function, add the following code.
using System.Threading;using System.Media;namespace Kai.Module.Boilerplate{
internal static class DefaultDataHandler
{
private const KaiCapabilities ModuleCapabilities = KaiCapabilities.GestureData;public static void Main(string[] args){KaiSDK.Initialise("<example-module-id>", "<example-module-secret>");InitialiseEvents();KaiSDK.DefaultKai.SetCapabilities(ModuleCapabilities);KaiSDK.Connect();Thread.Sleep(Timeout.Infinite); // prevent program from exiting}public static void InitialiseEvents(){// default kai event handler callbacksKaiSDK.DefaultKai.Gesture += GestureHandler;// universal error handlerKaiSDK.Error += ErrorHandler;}private static void GestureHandler(object e, GestureEventArgs gestureArg){
// Checkout: https://github.com/vicara-hq/kai-dotnet/blob/develop/Kai.BaseModule/Delegates.cs
// For specs of the eventArg classesLog.Info($"Gesture Event Triggered: {gestureArg.Gesture}");SoundPlayer player;switch(gestureArg.Gesture){case Gesture.SwipeUp:case Gesture.SideSwipeUp:player = new SoundPlayer(@"c:\one.wav");break;case Gesture.SwipeDown:case Gesture.SideSwipeDown:player = new SoundPlayer(@"c:\two.wav");break;case Gesture.SwipeLeft:case Gesture.SideSwipeLeft:player = new SoundPlayer(@"c:\three.wav");break;case Gesture.SwipeRight:case Gesture.SideSwipeRight:player = new SoundPlayer(@"c:\four.wav");break;default:return;}player.Play();}private static void ErrorHandler(object e, ErrorEventArgs errorArg){Log.Error($"Error: {errorArg.Error}");}}}

Voila! You’re done. You have now given the process of creating modules a ‘first try’. Once you’ve tried this out, you could then work on your own module. We hope this helps to kick things off!

For those of you who need more information, We have our trusty SDK documentation here. It covers pretty much everything you would need to know.

If you still need help, you can reach out to our development team at drift.me/vicara. We’re always around to help you get started!

Vicara

Vicara is an Immersive Technology Company that develops hardware products and solutions for Mixed Reality based Industrial applications.

Anupama Nair

Written by

Vicara

Vicara

Vicara is an Immersive Technology Company that develops hardware products and solutions for Mixed Reality based Industrial applications.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade