public static void ControlCmds(MotorCommands cmd) { switch(cmd) { case MotorCommands.Forward: InitRobot.Forward(); break; case MotorCommands.Reverse: InitRobot.Reverse(); break; case MotorCommands.Left: InitRobot.SpinLeft(); break; case MotorCommands.Right: InitRobot.SpinRight(); break; default: case MotorCommands.Stop: InitRobot.Stop(); break; } }
/// <summary> /// Sends the passed command and arguments to the microcontroller. If the array /// is null, then it is assumed the command does not take arguments. /// </summary> /// <param name="cmd">The command to send</param> /// <param name="bytes">The arguments to the command. If null, no arguments are sent</param> protected void command(MotorCommands cmd, byte[] bytes) { int size = (bytes == null ? 3 : bytes.Length + 3); byte[] cmdString = new byte[size]; cmdString[0] = (byte)MotorCommands.COMMAND_START; cmdString[1] = (byte) cmd; if (bytes != null) System.Array.Copy(bytes, 0, cmdString,2, bytes.Length); cmdString[size-1] = (byte)MotorCommands.COMMAND_STOP; Console.WriteLine("Sending Command: "); for (int i = 0; i < cmdString.Length; i++) { Console.WriteLine(cmdString[i]); } myMotors.Write(cmdString, 0, cmdString.Length); }
/* The only difference is the the below method. The rest of it is very similar to the GPS code */ protected void command(MotorCommands cmd, byte[] bytes) { int size = (bytes == null ? 3 : bytes.Length + 3); byte[] cmdString = new byte[size]; cmdString[0] = (byte)MotorCommands.COMMAND_START; cmdString[1] = (byte)cmd; //Console.WriteLine(cmdString[1]); //Console.WriteLine((byte)cmd); if (bytes != null) System.Array.Copy(bytes, 0, cmdString, 2, bytes.Length); cmdString[size-1] = (byte)MotorCommands.COMMAND_STOP; myMotors.Write(cmdString, 0, cmdString.Length); receive_log.AppendText("Command Length: " + cmdString.Length + "\n"); for (int i = 0; i < cmdString.Length; i++) { //Console.Write(cmdString[i] + " "); receive_log.AppendText(cmdString[i] + " "); } Console.WriteLine(); receive_log.AppendText("\n"); }