Skip to content

Commit

Permalink
CatAndMouse AI Demo - Cat AI
Browse files Browse the repository at this point in the history
  • Loading branch information
wenoptics committed Nov 21, 2019
1 parent 99c7b0d commit 1fc8d6d
Show file tree
Hide file tree
Showing 368 changed files with 119,604 additions and 445 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/OdysseyNowHAL.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/arduino-project-settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/dictionaries/graysonwen.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"board": "arduino:avr:mega",
"configuration": "cpu=atmega2560",
"port": "/dev/cu.usbmodem14201",
"port": "/dev/cu.usbmodem14401",
"sketch": "Arduino/OdysseyConController/OdysseyConController.ino"
}
20 changes: 10 additions & 10 deletions Arduino/OdysseyConController/OdysseyConController.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,27 @@ void processInData() {
docOut["error"] = parseError.c_str();
} else {

if ( ! docIn["P1_W"].isNull() ) {
if ( ! docIn["P1W"].isNull() ) {
// Re-init the play as input/output, (and make sure we don't do it if it's already in the state)
docIn["P1_W"].as<bool>() ? MAKE_WRITE(p1_spot) : MAKE_READ(p1_spot);
docIn["P1W"].as<bool>() ? MAKE_WRITE(p1_spot) : MAKE_READ(p1_spot);
reset_as_player(&p1_spot);
}
if ( ! docIn["P2_W"].isNull() ) {
docIn["P2_W"].as<bool>() ? MAKE_WRITE(p2_spot) : MAKE_READ(p2_spot);
if ( ! docIn["P2W"].isNull() ) {
docIn["P2W"].as<bool>() ? MAKE_WRITE(p2_spot) : MAKE_READ(p2_spot);
reset_as_player(&p2_spot);
}

if (p1_spot.writing) {
if (!(docIn["P1_X"].isNull() || docIn["P1_X"].isNull())) {
tmp_x = docIn["P1_X"];
tmp_y = docIn["P1_Y"];
if (!(docIn["P1X"].isNull() || docIn["P1X"].isNull())) {
tmp_x = docIn["P1X"];
tmp_y = docIn["P1Y"];
write_player_knobs(&p1_spot, tmp_x, tmp_y, 120); // todo - english
} // else { we have insufficient data received }
}
if (p2_spot.writing) {
if (!(docIn["P2_X"].isNull() || docIn["P2_X"].isNull())) {
tmp_x = docIn["P2_X"];
tmp_y = docIn["P2_Y"];
if (!(docIn["P2X"].isNull() || docIn["P2X"].isNull())) {
tmp_x = docIn["P2X"];
tmp_y = docIn["P2Y"];
write_player_knobs(&p2_spot, tmp_x, tmp_y, 120);
} // else { we have insufficient data received }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CMakeLists.txt not found in /Users/graysonwen/projects/VML/OdysseyNowHAL/Arduino/OdysseyConController Select CMakeLists.txt file...
Binary file added Arduino/doc/OdysseyNowArduinoMegaAddon.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions Arduino/doc/Read-Write-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Player spot Read/Write

The digital potentiometers are enabled or disabled
- when disabled, you can read from that player spot
- when enabled, that player spot is in write mode

there are 2 potentiometers for each player spot: one for horizontal position and one for vertical position.

(Levi)

[to disable the potentiometers] Disconnect the ground of the digital potentiometer and leave it floating. By disconnecting their ground and +5V sides from ground and +5V.

I do this using the GPIO pins of the arduino. When the pins are set to output, they provide ground or power to GND+VCC of the digital pot and GND of the Capacitor. But when the arduino pins are set to input, they go into a high impedance state essentially disconnection GND+VCC of the digital pot and GND of the capacitor, as if their wires were sticking up in the air. So then the digital pot and capacitor are connected to the Odyssey only on one end, there is no loop for current to flow through.
20 changes: 20 additions & 0 deletions Arduino/test_serial/test_serial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("ready.");
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()) {
Serial.println(Serial.available());
while(Serial.available()) {
Serial.print((char)Serial.read());
}
Serial.println("");
Serial.flush();
}

delay(1000);

}
42 changes: 42 additions & 0 deletions OdysseyNow/Assets/CatAI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class CatAI : MonoBehaviour
{

public GameObject target;
private NavMeshAgent agent;
public bool stop;


// Start is called before the first frame update
void Start()
{
// Agent tend to rotate game object, that can be
// undesirable
agent = GetComponent<NavMeshAgent>();
agent.updateRotation = false;
agent.updateUpAxis = false;
}

// Update is called once per frame
void Update()
{
if ((transform.position - target.transform.position).magnitude < 1 && !stop)
{
stop = true;
//target.GetComponent<Navigate>().enabled = false;
//Canvas canvas = FindObjectOfType<Canvas>();
//var gameOver = canvas.transform.Find("Panel");
//gameOver.gameObject.SetActive(true);
//var score = canvas.transform.Find("Score");
//score.SendMessage("Stop", true);

Debug.Log("Cat has the mouse.");
}
agent.SetDestination(target.transform.position);
//Navigate.DebugDrawPath(agent.path.corners);
}
}
11 changes: 11 additions & 0 deletions OdysseyNow/Assets/CatAI.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions OdysseyNow/Assets/GameLogic_CatAndMouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameLogic_CatAndMouse : MonoBehaviour
{
public GameObject player_mouse;
public GameObject player_cat;
public Collider2D wall;

public float p_distance;

Collider2D cod_mouse;
Collider2D cod_cat;

// Start is called before the first frame update
void Start()
{
// Player collider assignments
cod_cat = player_cat.GetComponentInChildren<Collider2D>();
cod_mouse = player_mouse.GetComponentInChildren<Collider2D>();
}

// Update is called once per frame
void Update()
{
this.p_distance = cod_cat.Distance(cod_mouse).distance;
if (this.p_distance < 0)
{
Debug.Log("Cat have the Mouse");
}

if (wall.Distance(cod_cat).distance < 0)
{
Debug.Log("Cat collide with the stone");
}

if (wall.Distance(cod_mouse).distance < 0)
{
Debug.Log("Mouse collide with the stone");
}

}
}
11 changes: 11 additions & 0 deletions OdysseyNow/Assets/GameLogic_CatAndMouse.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions OdysseyNow/Assets/GameReadyAssets/FurniturePack1.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions OdysseyNow/Assets/GameReadyAssets/FurniturePack1/Art.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions OdysseyNow/Assets/GameReadyAssets/FurniturePack1/Art/Chair01.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1fc8d6d

Please sign in to comment.