//car driving around the waypoints void AI_Update() { //avoidObject = GetComponent<ObstacleAvoid> ().avoidObstacle; //angleObject = GetComponent<ObstacleAvoid> ().angleObstacle; //posObject = GetComponent<ObstacleAvoid> ().obstaclePosition; leftObj = GetComponent <ObstacleAvoid> ().leftObs; centerObj = GetComponent <ObstacleAvoid> ().centerObs; rightObj = GetComponent <ObstacleAvoid> ().rightObs; LeftDis = GetComponent <ObstacleAvoid> ().LeftDis; RightDis = GetComponent <ObstacleAvoid> ().RightDis; CenterDis = GetComponent <ObstacleAvoid> ().CenterDis; rb.drag = rb.velocity.magnitude / 250; //Check if the next path segment needs to be calculated in a thread if (pathCalculated == false && jobInProgress == false) { //trigger thread job for this car to obtain the next set of waypoints Node pathStartNode; if (currentThreadJob.destinationNode == PathPlanningDataStructures.graph.endNode) { pathStartNode = startNode; } else { pathStartNode = currentThreadJob.destinationNode; } currentThreadJob = new DynamicPathThreadJob(pathStartNode, PathPlanningDataStructures.graph.endNode); currentThreadJob.Start(); jobInProgress = true; } //Check if in progress thread has completed the path calculation if (jobInProgress) { if (currentThreadJob.isFinished()) { nextWayPoints = currentThreadJob.getPathWayPoints(); pathCalculated = true; jobInProgress = false; Debug.Log("Finished next thread job. Size: " + nextWayPoints.Count); } } GoToWayPoint(); input_rpm = (GetCollider(0).rpm + GetCollider(1).rpm) / 2 * GearRatio [CurrGear]; ShiftGears(); GetCollider(0).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider(1).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider(2).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider(3).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider(0).brakeTorque = brake_power; GetCollider(1).brakeTorque = brake_power; GetCollider(2).brakeTorque = brake_power; GetCollider(3).brakeTorque = brake_power; GetCollider(0).steerAngle = maxSteer * input_steer; GetCollider(1).steerAngle = maxSteer * input_steer; //print (avoidObject); }
// <summary> // Performs path planning for the next path segment by utilizing a DynamicPathThreadJob // that calculates the path in the background // </summary> public void PathPlanNextSegment() { bool noItem = (GetComponent <PowerUp>().powerUp == ""); //Check if the next path segment needs to be calculated in a thread if (jobInProgress == false && nextWayPoints == null && dynamicReplan == false) { //trigger thread job for this car to obtain the next set of waypoints Node pathStartNode; if (currentThreadJob.destinationNode == PathPlanningDataStructures.graph.endNode) { pathStartNode = startNode; } else { pathStartNode = currentThreadJob.destinationNode; } currentThreadJob = new DynamicPathThreadJob(pathStartNode, PathPlanningDataStructures.graph.endNode, closedNodes, 12.0f, noItem); currentThreadJob.Start(); jobInProgress = true; } else if (jobInProgress == false && dynamicReplan) { Node pathStartNode; if (currentThreadJob.destinationNode == PathPlanningDataStructures.graph.endNode) { pathStartNode = startNode; } else { pathStartNode = PathPlanningDataStructures.graph.getClosestNode(transform.position + 3 * transform.forward); } currentThreadJob = new DynamicPathThreadJob(pathStartNode, PathPlanningDataStructures.graph.endNode, closedNodes, 5.0f, noItem); currentThreadJob.Start(); jobInProgress = true; } //Check if in progress thread has completed the path calculation if (jobInProgress) { if (currentThreadJob.isFinished()) { if (dynamicReplan) { dynamicWayPoints = currentThreadJob.getPathWayPoints(); nextWayPoints = null; } else { nextWayPoints = currentThreadJob.getPathWayPoints(); dynamicWayPoints = null; } closedNodes = currentThreadJob.getClosedNodes(); jobInProgress = false; } } }
//Determines the intial path segment for the car private void InitialPathPlan() { //first triggered thread job for this car startNode = PathPlanningDataStructures.graph.getClosestNode(transform.position); currentThreadJob = new DynamicPathThreadJob(startNode, PathPlanningDataStructures.graph.endNode); currentThreadJob.Start(); currentThreadJob.Join(); currentWayPoints = currentThreadJob.getPathWayPoints(); //indicate that next path segment needs to calculated pathCalculated = false; jobInProgress = false; }
// <summary> // Performs path planning for the first path segment by utilizing a DynamicPathThreadJob // and waiting for it to complete // </summary> public void PathPlanInitialSegment() { //first triggered thread job for this car startNode = PathPlanningDataStructures.graph.getClosestNode (transform.position); currentThreadJob = new DynamicPathThreadJob (startNode, PathPlanningDataStructures.graph.endNode, closedNodes, 15.0f, true); currentThreadJob.Start(); currentThreadJob.Join(); currentWayPoints = currentThreadJob.getPathWayPoints(); usesWaypoints = new bool[currentWayPoints.Count]; for (int i = 0; i < usesWaypoints.Length; i++) { usesWaypoints [i] = true; } closedNodes = currentThreadJob.getClosedNodes (); //indicate that next path segment needs to calculated jobInProgress = false; dynamicReplan = false; }
// <summary> // Performs path planning for the first path segment by utilizing a DynamicPathThreadJob // and waiting for it to complete // </summary> public void PathPlanInitialSegment() { //first triggered thread job for this car startNode = PathPlanningDataStructures.graph.getClosestNode(transform.position); currentThreadJob = new DynamicPathThreadJob(startNode, PathPlanningDataStructures.graph.endNode, closedNodes, 15.0f, true); currentThreadJob.Start(); currentThreadJob.Join(); currentWayPoints = currentThreadJob.getPathWayPoints(); usesWaypoints = new bool[currentWayPoints.Count]; for (int i = 0; i < usesWaypoints.Length; i++) { usesWaypoints [i] = true; } closedNodes = currentThreadJob.getClosedNodes(); //indicate that next path segment needs to calculated jobInProgress = false; dynamicReplan = false; }
// <summary> // Performs path planning for the next path segment by utilizing a DynamicPathThreadJob // that calculates the path in the background // </summary> public void PathPlanNextSegment() { bool noItem = (GetComponent<PowerUp>().powerUp == ""); //Check if the next path segment needs to be calculated in a thread if (jobInProgress == false && nextWayPoints == null && dynamicReplan == false) { //trigger thread job for this car to obtain the next set of waypoints Node pathStartNode; if (currentThreadJob.destinationNode == PathPlanningDataStructures.graph.endNode) { pathStartNode = startNode; } else { pathStartNode = currentThreadJob.destinationNode; } currentThreadJob = new DynamicPathThreadJob (pathStartNode, PathPlanningDataStructures.graph.endNode, closedNodes, 12.0f, noItem); currentThreadJob.Start (); jobInProgress = true; } else if (jobInProgress == false && dynamicReplan) { Node pathStartNode; if (currentThreadJob.destinationNode == PathPlanningDataStructures.graph.endNode) { pathStartNode = startNode; } else { pathStartNode = PathPlanningDataStructures.graph.getClosestNode(transform.position + 3 * transform.forward); } currentThreadJob = new DynamicPathThreadJob(pathStartNode, PathPlanningDataStructures.graph.endNode, closedNodes, 5.0f, noItem); currentThreadJob.Start (); jobInProgress = true; } //Check if in progress thread has completed the path calculation if (jobInProgress) { if (currentThreadJob.isFinished()) { if (dynamicReplan) { dynamicWayPoints = currentThreadJob.getPathWayPoints (); nextWayPoints = null; } else { nextWayPoints = currentThreadJob.getPathWayPoints(); dynamicWayPoints = null; } closedNodes = currentThreadJob.getClosedNodes (); jobInProgress = false; } } }
//Determines the intial path segment for the car private void InitialPathPlan() { //first triggered thread job for this car startNode = PathPlanningDataStructures.graph.getClosestNode (transform.position); currentThreadJob = new DynamicPathThreadJob (startNode, PathPlanningDataStructures.graph.endNode); currentThreadJob.Start(); currentThreadJob.Join(); currentWayPoints = currentThreadJob.getPathWayPoints(); //indicate that next path segment needs to calculated pathCalculated = false; jobInProgress = false; }
//car driving around the waypoints void AI_Update() { //avoidObject = GetComponent<ObstacleAvoid> ().avoidObstacle; //angleObject = GetComponent<ObstacleAvoid> ().angleObstacle; //posObject = GetComponent<ObstacleAvoid> ().obstaclePosition; leftObj = GetComponent<ObstacleAvoid> ().leftObs; centerObj = GetComponent<ObstacleAvoid> ().centerObs; rightObj = GetComponent <ObstacleAvoid> ().rightObs; LeftDis = GetComponent <ObstacleAvoid> ().LeftDis; RightDis = GetComponent<ObstacleAvoid> ().RightDis; CenterDis = GetComponent <ObstacleAvoid> ().CenterDis; rb.drag = rb.velocity.magnitude / 250; //Check if the next path segment needs to be calculated in a thread if (jobInProgress == false) { //trigger thread job for this car to obtain the next set of waypoints Node pathStartNode; if (currentThreadJob.destinationNode == PathPlanningDataStructures.graph.endNode) { pathStartNode = startNode; } else { pathStartNode = PathPlanningDataStructures.graph.getClosestNode (transform.position); } currentThreadJob = new DynamicPathThreadJob(pathStartNode, PathPlanningDataStructures.graph.endNode); currentThreadJob.Start(); jobInProgress = true; } //Check if in progress thread has completed the path calculation if (jobInProgress && nextWayPoints == null) { if (currentThreadJob.isFinished()) { nextWayPoints = currentThreadJob.getPathWayPoints(); jobInProgress = false; Debug.Log ("Finished next thread job. Size: " + nextWayPoints.Count); } } GoToWayPoint (); input_rpm = (GetCollider (0).rpm + GetCollider (1).rpm) / 2 * GearRatio [CurrGear]; ShiftGears (); GetCollider (0).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider (1).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider (2).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider (3).motorTorque = engineTorque / GearRatio [CurrGear] * input_torque; GetCollider (0).brakeTorque = brake_power; GetCollider (1).brakeTorque = brake_power; GetCollider (2).brakeTorque = brake_power; GetCollider (3).brakeTorque = brake_power; GetCollider (0).steerAngle = maxSteer * input_steer; GetCollider (1).steerAngle = maxSteer * input_steer; //print (avoidObject); }