Motorized Mario Kart
-
Motorized Mario Kart by Anika Vuurzoon
Anika Vuurzoon is a Mechanical Engineer from Eindhoven, The Netherlands, by
day. In her spare time, she designs rob...
1 day ago
until (SoundFlags() == SOUND_FLAGS_IDLE);
I found this in John Hansen's LEGO Mindstorms NXT Power Programming: Robotics in Ctask main() {
SetSensorTouch(S1);
// wait for the bumper to be touched
until(SENSOR_1);
// play a tone
PlayTone(330, MS_500);
// and start moving: go in a straight line; motors are oriented
// such a way that they need to go backwards for the robot to go forward
while(true) {
OnRevSync(OUT_BC, 75, 0);
// interesting: without the following Wait the robot doesn't start moving!
Wait(500);
// bumper was touched
until(SENSOR_1);
PlayFile("! Sonar.rso");
// go back one rotation (360 degrees)
RotateMotorEx(OUT_BC, 75, 360, 0, true, false);
int ending = 481, starting = 120;
unsigned int degrees = Random(ending-starting)+starting; // 120..480 inclusive
// turn around a random angle, between 120 and 480
RotateMotorEx(OUT_BC, -75, degrees, -100, true, false);
}
}
SetSensorTouch(S1);
SetSensor(S1, SENSOR_TOUCH);
ResetSensor(S1);
The call to SendResponseString will simply write the value of out (S1, S2, etc...) to the outbound or response mailbox numbered 11. Response mailboxes have numbers equal to the specified mailbox number plus 10. You actually have to pass the response mailbox number (i.e., 10..19) rather than the "regular" mailbox number (0..9), unless Mindsquals is doing something weird and adding 10 to the number you pass in (which it should not do).On the NXT side I stuck with the code I mentioned in my previous post (page 43 of Daniele Benedettelli's tutorial at bricxcc site):
//SLAVE
#define BT_CONN 1
#define INBOX 5
#define OUTBOX 1
task main(){
string in, out, iStr;
int i = 0;
while(true){
iStr = NumToStr(i);
out = StrCat("S",iStr);
ReceiveRemoteString(INBOX, true, in);
SendResponseString(OUTBOX,out);
TextOut(10,LCD_LINE3,in);
TextOut(10,LCD_LINE5,out);
Wait(100);
i++;
}
}
using NKH.MindSqualls;
namespace BTMasterMessage
{
public partial class Form1 : Form
{
............................
private void GetMessage()
{
byte comPort = byte.Parse(this.txtComPort.Text);
NxtCommunicationProtocol comm = new NxtBluetoothConnection(comPort);
comm.Connect();
string msg = comm.MessageRead(NxtMailbox2.Box1, NxtMailbox.Box0, true);
this.Text = msg;
}
}
}
string msg = comm.MessageRead(NxtMailbox2.Box11, NxtMailbox.Box0, true);