You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CozmoMovementController.cs 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ///-----------------------------------------------------------------
  2. /// Namespace: <Cozmo>
  3. /// Class: <CozmoMovementController>
  4. /// Description: <Statemachine to control the movement of the virtual cozmo.>
  5. /// Author: <Tobias Hassel> Date: <29.07.2019>
  6. /// Notes: <>
  7. ///-----------------------------------------------------------------
  8. ///
  9. using System;
  10. using UnityEngine;
  11. namespace Cozmo
  12. {
  13. // Different movementstates cozmo can use
  14. public enum MovementState { Stop, Forward, Right, Left }
  15. [RequireComponent(typeof(CozmoMovement))]
  16. public class CozmoMovementController : MonoBehaviour
  17. {
  18. [Tooltip("Current MovementState of the Robot. Change this to make the robot move.")]
  19. public MovementState currentMovementState = MovementState.Stop;
  20. private CozmoMovement movement; // Movement script of the robot
  21. void Start()
  22. {
  23. movement = GetComponent<CozmoMovement>();
  24. }
  25. private void FixedUpdate()
  26. {
  27. switch (currentMovementState)
  28. {
  29. case MovementState.Stop:
  30. movement.Move(0);
  31. break;
  32. case MovementState.Forward:
  33. movement.Move(1);
  34. break;
  35. case MovementState.Right:
  36. movement.Turn(1);
  37. break;
  38. case MovementState.Left:
  39. movement.Turn(-1);
  40. break;
  41. default:
  42. movement.Move(0);
  43. throw new ArgumentException("No real Movementstate was given. Default 'Stop' was chosen.");
  44. }
  45. }
  46. }
  47. }