Change directory to subfolder UnityProject

This commit is contained in:
Tobi
2019-08-24 23:01:28 +02:00
parent b7c8ed212a
commit fca6388ef2
3141 changed files with 0 additions and 0 deletions
@@ -0,0 +1,120 @@
///-----------------------------------------------------------------
/// Namespace: <Cozmo>
/// Class: <CozmoMovement>
/// Description: <Defines the possible movement of the virtual cozmo.>
/// Author: <Tobias Hassel> Date: <29.07.2019>
/// Notes: <>
///-----------------------------------------------------------------
///
using UnityEngine;
namespace Cozmo
{
public class CozmoMovement : MonoBehaviour
{
private const string MOVEMENT_AXIS_NAME = "Vertical"; // name of the movement input axis
private const string TURN_AXIS_NAME = "Horizontal"; // name of the rotation input axis
[Tooltip("Determines how fast the robot is moving forward and backwards.")]
public float m_Speed = 12f;
[Tooltip("Determines how fast the robot is turning in degrees per second.")]
public float m_TurnSpeed = 180f;
private Rigidbody cozmoRigidbody; // Reference to cozmos rigidbody
private float m_MovementInputValue; // current input value for movement
private float m_TurnInputValue; // current input value for rotation
private void Awake()
{
cozmoRigidbody = GetComponent<Rigidbody>();
}
private void OnEnable()
{
// When the cozmo is turned on, make sure it's not kinematic.
cozmoRigidbody.isKinematic = false;
// reset movement and rotation values
m_MovementInputValue = 0f;
m_TurnInputValue = 0f;
}
private void OnDisable()
{
// When the cozmo is turned off, set it to kinematic so it stops moving.
cozmoRigidbody.isKinematic = true;
}
private void Update()
{
// Store the value of both input axes.
m_MovementInputValue = Input.GetAxis(MOVEMENT_AXIS_NAME);
m_TurnInputValue = Input.GetAxis(TURN_AXIS_NAME);
}
private void FixedUpdate()
{
// Adjust position and rotation
Move();
Turn();
}
/// <summary>
/// Move the cozmo forward (0 < directionValue <= 1) or backwards (0 > directionvalue >= -1)
/// </summary>
/// <param name="directionValue"></param>
public void Move(float directionValue)
{
// clamp directionValue to make sure its between -1 and 1
Mathf.Clamp(directionValue, -1, 1);
Vector3 movement = directionValue * transform.forward * m_Speed * Time.deltaTime;
// Apply this movement to the rigidbody's position.
cozmoRigidbody.MovePosition(cozmoRigidbody.position + movement);
}
/// <summary>
/// Move cozmo based on the input value
/// </summary>
public void Move()
{
Move(m_MovementInputValue);
}
/// <summary>
/// Rotate cozmo based on the input value
/// </summary>
public void Turn()
{
Turn(m_TurnInputValue);
}
/// <summary>
/// Rotate cozmo
/// </summary>
/// <param name="turnValue"></param>
public void Turn(float turnValue)
{
// clamp turnValue to make sure its between -1 and 1
Mathf.Clamp(turnValue, -1, 1);
float turn = turnValue * m_TurnSpeed * Time.deltaTime;
// Make this into a rotation in the y axis.
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
// Apply this rotation to the rigidbody's rotation.
cozmoRigidbody.MoveRotation(cozmoRigidbody.rotation * turnRotation);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2056048a78a0cc4c97e7899ba1c0e31
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
///-----------------------------------------------------------------
/// Namespace: <Cozmo>
/// Class: <CozmoMovementController>
/// Description: <Statemachine to control the movement of the virtual cozmo.>
/// Author: <Tobias Hassel> Date: <29.07.2019>
/// Notes: <>
///-----------------------------------------------------------------
///
using System;
using UnityEngine;
namespace Cozmo
{
// Different movementstates cozmo can use
public enum MovementState { Stop, Forward, Right, Left }
[RequireComponent(typeof(CozmoMovement))]
public class CozmoMovementController : MonoBehaviour
{
[Tooltip("Current MovementState of the Robot. Change this to make the robot move.")]
public MovementState currentMovementState = MovementState.Stop;
private CozmoMovement movement; // Movement script of the robot
void Start()
{
movement = GetComponent<CozmoMovement>();
}
private void FixedUpdate()
{
switch (currentMovementState)
{
case MovementState.Stop:
movement.Move(0);
break;
case MovementState.Forward:
movement.Move(1);
break;
case MovementState.Right:
movement.Turn(1);
break;
case MovementState.Left:
movement.Turn(-1);
break;
default:
movement.Move(0);
throw new ArgumentException("No real Movementstate was given. Default 'Stop' was chosen.");
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d3ecda30187828846b48edbee97aebd7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,126 @@
///-----------------------------------------------------------------
/// Namespace: <CozmoHelpers>
/// Class: <CozmoMovementTester>
/// Description: <Used to measure the time for rotating and moving the virtual cozmo to copy the
/// real cozmos movement behaviour.>
/// Author: <Tobias Hassel> Date: <29.07.2019>
/// Notes: <>
///-----------------------------------------------------------------
///
using Cozmo;
using System.Diagnostics;
using UnityEngine;
namespace CozmoHelpers
{
public enum TestStates { MovementSpeed, RotationSpeed } // enum to determine test scenarios
[RequireComponent(typeof(CozmoMovement))]
public class CozmoMovementTester : MonoBehaviour
{
private const float DISTANCE_TO_MEASURE_SPEED = 1f; // Distance that is used to calculate cozmos movementspeed (in m)
private const float ROTATION_ANGLE = 90f; // Angle that is used to calculate cozmos rotationspeed
private CozmoMovement movement; // Reference to the movement script of cozmo
private Vector3 startPositionCozmo; // Original position of cozmo
private float lastY; // Last Y of cozmo
private Stopwatch movementWatch; // Stopwatch to measure the time for the movement usecase
private Stopwatch rotationWatch; // Stopwatch to measure the time for the rotation usecase
[Tooltip("Choose which speed of the virtual cozmo should be tested.")]
public TestStates testState = TestStates.MovementSpeed;
[Tooltip("Start and stop testing from the inspector.")]
public bool isTesting = false;
void Start()
{
movement = GetComponent<CozmoMovement>();
movementWatch = new Stopwatch();
rotationWatch = new Stopwatch();
startPositionCozmo = movement.transform.position; // Cache the starting position of Cozmo
lastY = movement.transform.rotation.y; // Cache the rotation Vector of Cozmo
}
private void FixedUpdate()
{
if (isTesting)
{
if (testState == TestStates.MovementSpeed)
{
TestMovementSpeed();
}
else if (testState == TestStates.RotationSpeed)
{
TestRotationSpeed();
}
}
}
// Measure time for rotation
private void TestRotationSpeed()
{
float currentY = movement.transform.rotation.eulerAngles.y;
// If distance between start and current position of cozmo reached the DISTANCE_TO_MEASURE_SPEED stop the stopwatch
if (currentY >= lastY + ROTATION_ANGLE || currentY <= lastY - ROTATION_ANGLE)
{
if (rotationWatch.IsRunning)
{
rotationWatch.Stop();
UnityEngine.Debug.Log("Cozmo: " + gameObject.name +
"\nElapsed time in milliseconds (Rotation): " + rotationWatch.ElapsedMilliseconds);
}
isTesting = false;
return;
}
else
{
// Start stopwatch to measure the time cozmo needs for a specific rotation
if (!rotationWatch.IsRunning)
{
rotationWatch = Stopwatch.StartNew();
}
// Turn right
movement.Turn(1);
}
}
// Measure time for movement
private void TestMovementSpeed()
{
// If distance between start and current position of cozmo reached the DISTANCE_TO_MEASURE_SPEED stop the stopwatch
if (Vector3.Distance(startPositionCozmo, movement.transform.position) >= DISTANCE_TO_MEASURE_SPEED)
{
if (movementWatch.IsRunning)
{
movementWatch.Stop();
UnityEngine.Debug.Log("Cozmo: " + gameObject.name +
"/nElapsed time in milliseconds (Movement): " + movementWatch.ElapsedMilliseconds);
}
isTesting = false;
return;
}
else
{
// Start stopwatch to measure the time cozmo needs for a specific distance
if (!movementWatch.IsRunning)
{
movementWatch = Stopwatch.StartNew();
}
// Move cozmo in forward direction
movement.Move(1);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4265d0764c65d26409f0f920e5293c82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: