MR Rube Goldberg Machine - Sensorycc/YUXI-Mixed-Reality-Hardware-Toolkit GitHub Wiki

Concept

We have taken inspiration from Rube Goldberg Machine. The bouncing ball in unity when falls on the plane, triggers the relay switch which turns on the fan. The fan which is part of the physical space then blows air to rotate the wings of paper, which create music. This in turn while rotating hits a ball which falls into the cup.

Image

Virtual ball hits plane and triggers the fan to move

Physical fan moves the artifact to kick the ball in the spoon

Technical Set Up

Power Relay

virtual world with relation to the physical world We have a bouncing ball (in unity) which when comes in collision with the ground triggers a button that turns on the fan in the physical space

How it works

When the bouncing ball in unity comes into contact with the surface of the plane; It sends a signal to the spacebrew; Raspberry pi is connected to the relay switch through the terminal; Terminal sends a signal to spacebrew; Spacebrew is the bridge between raspberry pi and unity and it combines the two.

Code for Unity

Add C# component to the ball object

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerController : MonoBehaviour {

public float speed;

private Rigidbody rb;

// Use this for initialization
SpacebrewEvents sbEvents;
//SpacebrewClient sbClient;

void Start () {
	rb = GetComponent<Rigidbody> ();
	GameObject go = GameObject.Find ("SpacebrewObject");
	sbEvents = go.GetComponent <SpacebrewEvents> ();
}




void OnCollisionEnter(Collision collision){
	Debug.Log("colliion started");
	//Check for a match with the specified name on any GameObject that collides with your GameObject


	//Check for a match with the specific tag on any GameObject that collides with your GameObject
	if (collision.gameObject.tag == "MyGameObjectTag")
	{
		//If the GameObject has the same tag as specified, output this message in the console
		Debug.Log("Do something else here");

	}
}

void OnCollisionStay (Collision collision){
	Debug.Log("Stay occuring..");
}

void OnCollisionExit (Collision collision)
{
	Debug.Log("Exit called...");
	//sbEvents.sendPhysicalEvent();

	if (collision.gameObject.name == "Cube")
	{
		//If the GameObject's name matches the one you suggest, output this message in the console
		Debug.Log("Do something here");
		sbEvents.sendPhysicalEvent();
	}
}


// Update is called once per frame

void FixedUpdate() {
	float moveHorizontal = Input.GetAxis ("Horizontal");
	float moveVertical = Input.GetAxis ("Vertical");

	Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

	rb.AddForce (movement * speed);
}

} ##Spacebrew Events Code using UnityEngine; using System.Collections;

public class SpacebrewEvents : MonoBehaviour {

SpacebrewClient sbClient;
bool lightState = false;

/*

Ok, let's do this all in one script?

BaseExample: None? HelloWorld P: None S: launchSatellite, string LightsButtons P: buttonPress, boolean S: flipLight, boolean SenseHat P: letter, string S: direction, string up,down,left,right,middle (default) S: layer, string

p:2 s:4

*/

// Use this for initialization
void Start () {
	GameObject go = GameObject.Find ("SpacebrewObject"); // the name of your client object
	sbClient = go.GetComponent <SpacebrewClient> ();

	// register an event with the client and a callback function here.
	// COMMON GOTCHA: THIS MUST MATCH THE NAME VALUE YOU TYPED IN THE EDITOR!!
	sbClient.addEventListener (this.gameObject, "launchSatellite");
	sbClient.addEventListener (this.gameObject, "flipLight");
	sbClient.addEventListener (this.gameObject, "letters");
}

// Update is called once per frame
void Update () {
	if (Input.GetKeyDown ("space")) {
		print ("Sending Spacebrew Message");
		// name, type, value
		// COMMON GOTCHA: THIS MUST MATCH THE NAME VALUE YOU TYPED IN THE EDITOR!!
		//sbClient.sendMessage("buttonPress", "boolean", "true");
	}
	foreach (char c in Input.inputString) {
		print("Just pressed: "+c.ToString());
		if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') {
			sbClient.sendMessage("letters", "string", c.ToString());
			GameObject go = GameObject.Find ("MatrixContainer"); // the name of your client object
			MatrixMaker grid = go.GetComponent <MatrixMaker> ();
			grid.ParseIncomingLetter(c.ToString());
			grid.delayLayer();
			//grid.CreateLayer(true);
			
		}
	}

	if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began) {
		sbClient.sendMessage("buttonPress", "boolean", "true");
	}
	if(Input.GetMouseButtonDown(0)){
		sbClient.sendMessage("buttonPress", "boolean", "true");
	}

	
}

void OnApplicationQuit () {
	sbClient.sendMessage("buttonPress", "boolean", "true");
}

public void sendPhysicalEvent() {
	sbClient.sendMessage("buttonPress", "boolean", "true");
}

public void OnSpacebrewEvent(SpacebrewClient.SpacebrewMessage _msg) {


	print ("Received Spacebrew Message");
	print (_msg);

	// Look for incoming Satellite messages
	if (_msg.name == "launchSatellite") {
		if (_msg.value == "true") {
			GameObject go = GameObject.Find("BaseBoARd/YourObjectsGoHere/CenterOfUniverse");
			OrbitManager om = go.GetComponent <OrbitManager> ();
			om.makeSatellite();
			print("Tried to launch Satellite");
		}
	}

	// Look for messages to turn the virtual lamp light on
	if (_msg.name == "letters") {
		GameObject go = GameObject.Find ("MatrixContainer"); // the name of your client object
		MatrixMaker grid = go.GetComponent <MatrixMaker> ();
		grid.ParseIncomingLetter(_msg.value[0].ToString());
		grid.delayLayer();
	}

	// Look for messages to turn the virtual lamp light on
	if (_msg.name == "flipLight") {
		//print(go);
		if (_msg.value == "true") {
			GameObject go = GameObject.Find("BaseBoARd/YourObjectsGoHere/Lamp/SpacebrewSpotlight");
			lightState = !lightState;
			go.gameObject.SetActive(lightState);
		}
	}



	//if (_msg.name == "letters") {
	//print(go);
	//if (_msg.value == "true") {
	// GameObject go = GameObject.Find ("MatrixContainer"); // the name of your client object
	// MatrixMaker grid = go.GetComponent <MatrixMaker> ();
	// grid.CreateLayer(true);
	// grid.ParseIncomingString(_msg.value);
}

}

⚠️ **GitHub.com Fallback** ⚠️