/// <summary> /// This function enables synchonizing two motors. /// Synchonization should be used when motors should run as synchrone as possible, /// </summary> /// <param name="socket">socket for executing command to brick</param> /// <param name="layer">Specify chain layer number [0 - 3]</param> /// <param name="ports">Output bit field [0x00 – 0x0F]</param> /// <param name="speed">Speed level, [-100 – 100]</param> /// <param name="turnRatio">Turn ratio, [-200 - 200] /// 0 : Motor will run with same power /// 100 : One motor will run with specified power while the other will be close to zero /// 200: One motor will run with specified power forward while the other will run in the opposite direction at the same power level. /// </param> /// <param name="time">Time in milliseconds, 0 = Infinite</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> /// <remarks> /// Instruction opOutput_Time_Sync (LAYER, NOS, SPEED, TURN, STEP, BRAKE) /// Opcode 0xB1 /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3] /// (Data8) NOS – Output bit field [0x00 – 0x0F] /// (Data8) SPEED – Power level, [-100 – 100] /// (Data16) TURN – Turn ratio, [-200 - 200], see documentation below /// (Data32) TIME – Time in milliseconds, 0 = Infinite /// (Data8) BRAKE - Specify break level [0: Float, 1: Break] /// Dispatch status Unchanged /// Description This function enables synchonizing two motors. Synchonization should be used when motors should run as synchrone as possible, /// </remarks> public static async Task TimeSync(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, int turnRatio, int time, Brake brake = Brake.Float, bool requireReply = true) { if (time < 0) { throw new ArgumentOutOfRangeException(nameof(time), ">=0"); } if (speed < -100 || speed > 100) { throw new ArgumentOutOfRangeException(nameof(speed), "[-100,100]"); } if (turnRatio < -200 || turnRatio > 200) { throw new ArgumentOutOfRangeException(nameof(turnRatio), "[-200,200]"); } Command cmd = null; using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY)) { cb.OpCode(OP.opOUTPUT_TIME_SYNC); cb.SHORT((int)layer); cb.SHORT((int)ports); cb.PAR8(speed); cb.PAR16(turnRatio); cb.PAR32(time); cb.PAR8((byte)brake); cmd = cb.ToCommand(); } await socket.Execute(cmd); }
/// <summary> /// This function enables specifying a full motor power cycle in time. /// RampUp specifies the power ramp up periode in milliseconds, /// ContinuesRun specifies the constant power period in milliseconds, /// RampDown specifies the power down period in milliseconds. /// </summary> /// <param name="socket">socket for executing command to brick</param> /// <param name="layer">Specify chain layer number [0 - 3]</param> /// <param name="ports">Output bit field [0x00 – 0x0F]</param> /// <param name="power">Specify output power [-100 – 100]</param> /// <param name="timeRampUp">Time in milliseconds for ramp up</param> /// <param name="timeContinuesRun">Time in milliseconds for continues run</param> /// <param name="timeRampDown">Time in milliseconds for ramp down</param> /// <param name="brake">Specify break level, [0: Float, 1: Break]</param> /// <remarks> /// Instruction opOutput_Time_Power (LAYER, NOS, POWER, STEP1, STEP2, STEP3, BRAKE) /// Opcode 0xAD /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3] /// (Data8) NOS – Output bit field [0x00 – 0x0F] /// (Data8) POWER – Power level, [-100 – 100] /// (Data32) STEP1 – Time in milliseconds for ramp up /// (Data32) STEP2 – Time in milliseconds for continues run /// (Data32) STEP3 – Time in milliseconds for ramp down /// (Data8) BRAKE - Specify break level [0: Float, 1: Break] /// Dispatch status Unchanged /// Description This function enables specifying a full motor power cycle in time. Step1 specifies the power ramp up periode in milliseconds, Step2 specifies the constant power period in milliseconds, Step 3 specifies the power down period in milliseconds. /// </remarks> public static async Task TimePower(ISocket socket, ChainLayer layer, OutputPortFlag ports, int power, int timeRampUp, int timeContinuesRun, int timeRampDown, Brake brake = Brake.Float, bool requireReply = true) { if (power < -100 || power > 100) { throw new ArgumentOutOfRangeException(nameof(power), "[-100,100]"); } if (timeContinuesRun < 0) { throw new ArgumentOutOfRangeException(nameof(timeContinuesRun), ">=0"); } if (timeRampUp < 0) { throw new ArgumentOutOfRangeException(nameof(timeRampUp), ">=0"); } if (timeRampDown < 0) { throw new ArgumentOutOfRangeException(nameof(timeRampDown), ">=0"); } Command cmd = null; using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY)) { cb.OpCode(OP.opOUTPUT_TIME_POWER); cb.SHORT((int)layer); cb.SHORT((int)ports); cb.PAR8(power); cb.PAR32(timeRampUp); cb.PAR32(timeContinuesRun); cb.PAR32(timeRampDown); cb.PAR8((byte)brake); cmd = cb.ToCommand(); } await socket.Execute(cmd); }
/// <summary> /// This function enables the program to clear the tacho count used as sensor input. /// </summary> /// <param name="socket">socket for executing command to brick</param> /// <param name="layer">Specify chain layer number [0 - 3]</param> /// <param name="ports">Output bit field [0x00 – 0x0F]</param> /// <remarks> /// Instruction opOutput_Clr_Count (LAYER, NOS) /// Opcode 0xB2 /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3] /// (Data8) NOS – Output bit field [0x00 – 0x0F] /// Dispatch status Unchanged /// Description This function enables the program to clear the tacho count used as sensor input. /// </remarks> public static async Task ResetTachoCount(ISocket socket, ChainLayer layer, OutputPortFlag ports, bool requireReply = true) { Command cmd = null; using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY)) { cb.OpCode(OP.opOUTPUT_CLR_COUNT); cb.SHORT((int)layer); cb.SHORT((int)ports); cmd = cb.ToCommand(); } await socket.Execute(cmd); }
/// <summary> /// This function sends stop to all individual output ports /// </summary> /// <param name="socket">socket for executing command to brick</param> /// <param name="layer">Specify chain layer number [0 - 3]</param> /// <param name="ports">Output bit field [0x00 – 0x0F]</param> /// <param name="brake">Specify break level [0: Float, 1: Break]</param> /// <remarks> /// Instruction opOutput_Stop (LAYER, NOS, BRAKE) /// Opcode 0xA3 /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3] /// (Data8) NOS – Output bit field [0x00 – 0x0F] /// (Data8) BRAKE – Specify break level [0: Float, 1: Break] /// Dispatch status Unchanged /// Description This function enables restting the tacho count for the individual output ports /// </remarks> public static async Task Stop(ISocket socket, ChainLayer layer, OutputPortFlag ports, Brake brake = Brake.Float, bool requireReply = true) { Command cmd = null; using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY)) { cb.OpCode(OP.opOUTPUT_STOP); cb.SHORT((int)layer); cb.SHORT((int)ports); cb.PAR8((byte)brake); cmd = cb.ToCommand(); } await socket.Execute(cmd); }
/// <summary> /// This function enables specifying the output device type /// </summary> /// <param name="socket">socket for executing command to brick</param> /// <param name="layer">Specify chain layer number [0 - 3]</param> /// <param name="port">Port number [0 - 3]</param> /// <param name="type">Output device type, (0x07: Large motor, Medium motor = 0x08)</param> /// <param name="requireReply">indicate if the brick should respond OK on method call</param> /// <remarks> /// Instruction opOutput_Set_Type (LAYER, NO, TYPE) /// Opcode 0xA1 /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3] /// (Data8) NO – Port number [0 - 3] /// (Data8) TYPE – Output device type, (0x07: Large motor, Medium motor = 0x08) /// Dispatch status Unchanged /// Description This function enables specifying the output device type /// </remarks> public static async Task SetType(ISocket socket, ChainLayer layer, OutputPortName port, DeviceType type, bool requireReply = true) { Command cmd = null; using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY)) { cb.OpCode(OP.opOUTPUT_SET_TYPE); cb.SHORT((int)layer); cb.SHORT((int)port); cb.PAR8((byte)type); cmd = cb.ToCommand(); } await socket.Execute(cmd); }
/// <summary> /// This function enables setting the output percentage speed on the output ports. /// This automatically enables speed control, which means the system will automatically adjust the power to keep the specified speed. /// </summary> /// <param name="socket">socket for executing command to brick</param> /// <param name="layer">Specify chain layer number [0 - 3]</param> /// <param name="ports">Output bit field [0x00 – 0x0F]</param> /// <param name="speed">Specify output speed [-100 – 100 %]</param> /// <remarks> /// Instruction opOutput_Speed (LAYER, NOS, SPEED) /// Opcode 0xA5 /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3] /// (Data8) NOS – Output bit field [0x00 – 0x0F] /// (Data8) SPEED – Specify output speed [-100 – 100 %] /// Dispatch status Unchanged /// Description This function enables setting the output percentage speed on the output ports. This modes automatically enables speed control, which means the system will automa-tically adjust the power to keep the specified speed. /// </remarks> public static async Task SetSpeed(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, bool requireReply = true) { if (speed < -100 || speed > 100) { throw new ArgumentException(nameof(speed), "[-100 and 100]"); } Command cmd = null; using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY)) { cb.OpCode(OP.opOUTPUT_SPEED); cb.SHORT((int)layer); cb.SHORT((int)ports); cb.PAR8(speed); cmd = cb.ToCommand(); } await socket.Execute(cmd); }