| |
Robot driving using I2C device - Stop driving
1. Start "SPL script editor for MSRDS" and add SPL simulation script
- Add below script on the editor (same script with the previous tutorial).
| |
MFEmulator emul1
/TargetEmulator:SPLMFConsoleEmulator
/Procedure_I2CWrite:proc_i2c_write
StartSimulationEngine "SimState/basicenv4.xml"
AddDifferentialDriveEntity base1
FlushScript
Procedure proc_i2c_write
if (value.Id == "i2c1")
{
left_power = value.ReceivedBytes[0]
right_power = value.ReceivedBytes[1]
left_power = left_power - 100
right_power = right_power - 100
left_power = Util.ToDouble(left_power / 100.0)
right_power = Util.ToDouble(right_power / 100.0)
print "Left -> " + left_power.ToString() + " / Right -> " + right_power.ToString()
}
base1.Go(left_power, right_power)
End
| |
|
- Save script.
- Press "F5" key or click "Run" icon.
2. Send data to emulator through I2C device
- Clear editor box of MF application.
- Add below script on the editor box of MF application.
| |
I2CDevice i2c1
/Address:58
/ClockRateKhz:100
buff1 = Util.CreateArrayByte(2)
buff1[0] = 130
buff1[1] = 130
i2c1.Write(buff1)
| |
|
- Value 130 will be converted as 0.3 in the MSRDS SPL procedure.
- Click "Send to MF Application" button
3. Make a robot stop
- Clear editor box of MF application.
- In order to make a robot stop, add below script on the editor box of MF application.
| |
buff1[0] = 100
buff1[1] = 100
i2c1.Write(buff1)
| |
|
- Value 100 will be converted as 0.0 in the MSRDS SPL procedure.
- Click "Send to MF Application" button
- You can see a mobile robot stop.
|