//Execute l'action envoyée en paramètre private void executeAction(NXTAction action) { char actiontd = action.Action; NXTCase caseCur = currentCase(); Point newDir = ERROR; if (actiontd != NXTMovement.PAUSE) { newDir = caseCur.goThrough(action, this.direction); } //Console.WriteLine(this.position); if (newDir != ERROR && action.Movement != NXTMovement.UTURN) { this.position = this.position + newDir; } if (actiontd != NXTMovement.PAUSE) { this.direction = newDir; } if (actiontd == NXTAction.TAKE) { this.takePatient(this.position); } else if (actiontd == NXTAction.DROP) { this.dropPatient(); } }
// Envoie le paquet de la prochaine action à effectuer (true), ou renvoie false si il n'y a plus d'actions public bool SendNextAction(bool simulation = false) { NXTAction action = this.executeCommand(); if (action != null) { Console.WriteLine("Ordre envoyé: " + action.ToString()); if (action.Movement == NXTMovement.PAUSE) { Sleep(action.Temporisation); } if (!simulation && action.Action != NXTAction.PAUSE) { NXTPacket packet = new NXTPacket(action); nxtHelper.SendNTXPacket(packet); } return(true); } else { return(false); } }
// -------------------------------------------------------------------------- // CONSTRUCTOR // -------------------------------------------------------------------------- public RemoteWindow(NXTVehicule vehicule) { InitializeComponent(); this.vehicule = vehicule; pStraight = new NXTAction(NXTMovement.STRAIGHT); pLeft = new NXTAction(NXTMovement.INTER_LEFT); pRight = new NXTAction(NXTMovement.INTER_RIGHT); pUturn = new NXTAction(NXTMovement.UTURN); }
public IA(NXTVehicule p_vehicule, bool p_simulation = false) { this.vehicule = p_vehicule; this.circuit = vehicule.Circuit; this.buffer = p_vehicule.Buffer; pStraight = new NXTAction(NXTMovement.STRAIGHT); pLeft = new NXTAction(NXTMovement.INTER_LEFT); pRight = new NXTAction(NXTMovement.INTER_RIGHT); pUturn = new NXTAction(NXTMovement.UTURN); }
// Retourne la prochaine action à executer, ou null si il n'y a pas d'action public NXTAction executeCommand() { NXTAction action = null; if (!buffer.isEmpty()) { action = buffer.Pop(); executeAction(action); } return(action); }
// Bouton "drop" private void Button6_Click(object sender, EventArgs e) { if (!vehicule.Buffer.isEmpty()) { NXTAction a = vehicule.Buffer.Last().Duplicate(); a.Action = NXTAction.DROP; vehicule.Buffer.RemoveAt(vehicule.Buffer.Count - 1); vehicule.addToBuffer(a); } UpdateBuffer(vehicule.Buffer); }
//Retourne le point correspondant au déplacement effectu� dans la case selon l'action donn�e en param�tre public Point goThrough(NXTAction action, Point direction) { char movement = action.Movement; if (movement == NXTMovement.STRAIGHT) { return(goStraight(direction)); } else if (movement == NXTMovement.INTER_LEFT || movement == NXTMovement.INTER_RIGHT) { return(turnInter(direction, movement)); } else if (movement == NXTMovement.UTURN) { return(goUTurn(direction)); } return(NXTVehicule.ERROR); }
// Ajoute une action au buffer du vehicule public void addToBuffer(NXTAction action) { this.buffer.Add(action, false); }
// -------------------------------------------------------------------------- // CONSTRUCTOR // -------------------------------------------------------------------------- public NXTPacket(NXTAction action) { this.action = action; }
protected NXTAction MovementToAction(NXTCase currentCase, Point currentPosition, Point currentDirection, Point destination, out Point newDirection) { NXTAction outInstance = null; newDirection = currentDirection; Point deplacement = destination - currentPosition; Point caseDirection = OrientationToDirection(currentCase.CaseOrientation); //Si le robot doit marquer une pause if (destination.Equals(currentPosition)) { outInstance = new NXTAction(NXTMovement.PAUSE); } // Si destination derriere direction actuelle, demi tour if (destination.Equals(currentPosition - currentDirection)) { outInstance = new NXTAction(NXTMovement.UTURN); } // Sinon si virage ou tout droit envoyer straight else if (currentCase.TypeCase == Case.STRAIGHT || currentCase.TypeCase == Case.VIRAGE) { outInstance = new NXTAction(NXTMovement.STRAIGHT); if (currentCase.TypeCase == Case.VIRAGE) { newDirection = currentCase.goThrough(new NXTAction(NXTMovement.STRAIGHT), currentDirection); } } // sinon (intersection) else { //Console.WriteLine("[INTERSECTION] Deplacement= " + deplacement); // Si la case est dans la meme direction que le vehicule if (caseDirection.Equals(currentDirection)) { if (deplacement.Equals(Rotate90Clockwise(currentDirection))) { outInstance = new NXTAction(NXTMovement.INTER_RIGHT); newDirection = Rotate90Clockwise(currentDirection); } else { outInstance = new NXTAction(NXTMovement.INTER_LEFT); newDirection = Rotate90AntiClockwise(currentDirection); } } else if (caseDirection.Equals(Rotate90Clockwise(currentDirection))) // r = tout droit { if (deplacement.Equals(Rotate90AntiClockwise(currentDirection))) { outInstance = new NXTAction(NXTMovement.INTER_LEFT); newDirection = Rotate90AntiClockwise(currentDirection); } else { outInstance = new NXTAction(NXTMovement.INTER_RIGHT); } } else if (caseDirection.Equals(Rotate90AntiClockwise(currentDirection))) // l = tout droit { if (deplacement.Equals(Rotate90Clockwise(currentDirection))) { outInstance = new NXTAction(NXTMovement.INTER_RIGHT); newDirection = Rotate90Clockwise(currentDirection); } else { outInstance = new NXTAction(NXTMovement.INTER_LEFT); } } } //Console.WriteLine(currentCase + " @ " + currentPosition + " -> " + destination + " _ " + DirectionToOrientation(newDirection) + "\nResult= " + outInstance); return(outInstance); }