text: tag:blogger.com,1999:blog-64739155845917041332016-09-07T21:26:46.115-07:00my NXTingmerlin13 default path for Lego Mindstorms NXTEvery time I open the Mindstorms software the default path points to the home folder of a user that doesn't even exist on my laptop (I assume this is because I installed the software a while back when this user existed but in the meantime I deleted it) so each time I want to save a new program I have to browse to the real path. I looked around and found <a target="_blank" href="">these directions</a> about how to change it: all I had to do is edit the 'settings.ini' file in "C:\documents and settings\%username%\My Documents\Lego Creations\Mindstorms Projects\Profiles\Default\" and change the "DataGetting Groovy</a><br /><LI><a href="" target="_blank">GitMagic</a><br /></UL>merlin13 NXC - part 2This idea to try to rewrite NXT-G programs from David J.Perdue's <a target="_blank" href="">The Unofficial LEGO MINDSTORMS NXT Inventor's Guide</a><img src="" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important; padding: 0px !important" /> using NXC really helps me learn. I just did this for the ClawBot1 program (which you can find in the chapter 11-16 source code archive on <a href="" target="_blank">this page</a>) and it was a lot faster than my initial try for the BumperBot. The code is on Google code <a href="" target="_blank">here</a>.<br /><br />Nothing fancy, just 3 things I want to mention so I don't forget:<br /><ol><li.<br /><li>The equivalent of NXT-G's "Wait for completion" when playing a sound file is this:<br /><code><pre>until (SoundFlags() == SOUND_FLAGS_IDLE);</pre></code>I found this in John Hansen's <a target="_blank" href="">LEGO Mindstorms NXT Power Programming: Robotics in C</a><img src="" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important; padding: 0px !important" /> book and it is a great find: thanks, John!<br /><li.<br /></ol>Update: I just finished the NXC version of ClawBot2 program in 2 versions: <a href="" target="_blank">everything in main()</a> and <a href="" target="_blank">using a function</a> (I noticed that some of the actions were common with only a couple of differences so I tried to use a function with 2 arguments and it worked great).merlin13 NXCIn the past few weeks I got 2 Mindstorms NXT books, both of them great: <a target="_blank" href="">LEGO Mindstorms NXT Power Programming: Robotics in C</a><img src="" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important; padding: 0px !important" /> by John Hansen and David J.Perdue's <a target="_blank" href="">The Unofficial LEGO MINDSTORMS NXT Inventor's Guide</a><img src="" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important; padding: 0px !important" />. I am right now reading both of them in an effort to learn more about building NXT robots and both NXT-G and NXC programming.<br /><br />I just built and programmed the BumperBot with the second program from David's book (which you can find in the chapter 11-16 source code archive on <a href="" target="_blank">this page</a>; named Bumper-Bot2) and I decided to try to learn NXC by "translating" this program. I read a lot of John's book already but it is quite different to try to write something vs. just understanding the code in the book.<br /><br />And I did it! The program I came up with is this (also on Google code <a href="" target="_blank">here</a>):<br /><code><pre>task main() {<br /><br /> SetSensorTouch(S1);<br /> // wait for the bumper to be touched<br /> until(SENSOR_1);<br /> // play a tone<br /> PlayTone(330, MS_500);<br /> // and start moving: go in a straight line; motors are oriented<br /> // such a way that they need to go backwards for the robot to go forward<br /> while(true) {<br /> OnRevSync(OUT_BC, 75, 0);<br /> // interesting: without the following Wait the robot doesn't start moving!<br /> Wait(500);<br /> // bumper was touched<br /> until(SENSOR_1);<br /> PlayFile("! Sonar.rso");<br /> // go back one rotation (360 degrees)<br /> RotateMotorEx(OUT_BC, 75, 360, 0, true, false);<br /> int ending = 481, starting = 120;<br /> unsigned int degrees = Random(ending-starting)+starting; // 120..480 inclusive<br /> // turn around a random angle, between 120 and 480<br /> RotateMotorEx(OUT_BC, -75, degrees, -100, true, false);<br /> }<br />}<br /></pre></code><br />Nothing really special, you've more than likely seen more advanced NXC code on the web. But it's worth noticing a few things:<br /><ul><li.<br /><br /><b>Update</b>: Digging through the NXC API with the help of John Hansen's excellent <a href="" target="_blank">NXC Programmer's Guide</a>, I noticed a ResetSensor function. I gave it a try thinking that it may help with my original problem and it did. So, basically, to setup the touch sensor I was able to use the version above:<br /><code><pre>SetSensorTouch(S1);</pre></code><br />but it also works like this:<br /><code><pre>SetSensor(S1, SENSOR_TOUCH);<br />ResetSensor(S1);</pre></code><br />I'm glad I discovered this since I haven't seen any example like it or notes about this behavior anywhere.<br /><li>In the while block, if the Wait() statement is not present, the first robot move command doesn't do anything. I am not sure why this is the case but it was quite puzzling for a while, why the robot didn't move when the command was there.<br /><li>Last thing: in the beginning, I followed the blocks in the NXT-G program to a "t" so the RotateMotorEx commands had the last argument set to <i>true</i> (to break the motors). But I noticed that the robot was moving more jerkily with the NXC program compared to the NXT-G one; so, I changed it to <i>false</i> (meaning Coast). I am still not sure why the difference, why Break in NXT-G seems to move the robot smoother than Break in NXC.<br /></UL>Like I said when I started this blog: these short articles are both for my benefit, to write down what I learned so I can remember it next time, and for you the reader's benefit, if you find anything useful here. This short exercise of rewriting an NXT-G program in NXC seemed a no brainer at the beginning but I definitely learned a few things while doing it.merlin13 rocks! NXTasy.org does, too!Now that I decided on using <a href="">MindSqualls</a>, let's get coding. First stumble block was the MessageRead() method takes as a second argument the local mailbox. What is the local mailbox? I decided to ask in the NXTasy forum and John Hansen promptly replied saying that the local mailbox should be ignored because there isn't one. He also mentioned something else that at the time I didn't understand:<br /><blockquote>The).</blockquote>On the NXT side I stuck with the code I mentioned in my previous post (page 43 of Daniele Benedettelli's <a href="">tutorial at bricxcc site</a>):<br /><code><br /><pre>//SLAVE<br />#define BT_CONN 1<br />#define INBOX 5<br />#define OUTBOX 1<br /><br />task main(){<br /> string in, out, iStr;<br /> int i = 0;<br /> while(true){<br /> iStr = NumToStr(i);<br /> out = StrCat("S",iStr);<br /> ReceiveRemoteString(INBOX, true, in);<br /> SendResponseString(OUTBOX,out);<br /> TextOut(10,LCD_LINE3,in);<br /> TextOut(10,LCD_LINE5,out);<br /> Wait(100);<br /> i++;<br /> }<br />}</pre></code><br />On the PC side I wrote something really simple (please note that I am using this code only as a rough example, it is by no means 100% functional, large sections were left out):<br /><code><pre>using NKH.MindSqualls;<br /><br />namespace BTMasterMessage<br />{<br /> public partial class Form1 : Form<br /> {<br /> ............................<br /> private void GetMessage()<br /> {<br /> byte comPort = byte.Parse(this.txtComPort.Text);<br /> NxtCommunicationProtocol comm = new NxtBluetoothConnection(comPort);<br /> comm.Connect();<br /> string msg = comm.MessageRead(NxtMailbox2.Box1, NxtMailbox.Box0, true);<br /> this.Text = msg;<br /> }<br /> }<br />}<br /></pre></code><br />Well, nothing worked, there was no message displayed PC side. Then I read more closely what John mentioned in his answer and I decided to change the first argument of MessageRead from Box1 to Box11:<br /><code><pre>string msg = comm.MessageRead(NxtMailbox2.Box11, NxtMailbox.Box0, true);</pre></code><br />It was a magical moment when I ran the program and I got an "S173" or something like it on my screen. It was so awesome!<br /><br />The conclusion: MindSqualls rocks and the helpful and friendly people in the NXTasy forum do as well! Big thanks to both teams!merlin13 with Bluetooth.<br /><br / <a href="">tutorial at bricxcc site</a> (page 43) that is supposed to receive a message from another NXT and send a response message back.<br /><br /.<br /><br /.<br /><br />Looking around I found several libraries that seemed able to use mailboxes, a comprehensive list is <a href="">here</a> on Team Hassenplug's site. I decided that if Java didn't work, maybe I should try C# (which I don't know but it is close to Java as far as I know) so I decided to try <a href="">MindSqualls</a> (another alternative seems to be NXT# but the website was down every time I tried).<br /><br />So, it is MindSqualls' turn. But about this, in a later post.merlin13 great book and a solution to my Bluetooth problemA few weeks ago I've seen in a local bookstore <a href="">Daniele Benedettelli</a>'s <a href="" target="_blank">Creating Cool MINDSTORMS NXT Robots </a>book and I loved it from the moment I opened it. I purchased a copy and started reading it and immediately I was very happy with it: the way theory aspects are presented and explained, the building instructions, the code, everything is really accessible.<br /><br /!<br /><br />Those of you that don't have this book but have problems connecting via Bluetooth can find help in John Hansen's <a href="">article on nxtasy.org </a>merlin13 it all startedI am a beginner with electronics, microcontrollers, robots, LEGOs... you name it. But I want to learn! So a couple years back when I decided to get on with it, I looked around and found <a href="">David Cook</a>'s <a href="" target="_blank">Robot Building for Beginners</a> %.<br /><br />The experience and the amount of learning was great! I figured the next step was to build a robot using a microcontroller. I started playing with ATmega's and TI's MSP430 and again I learned a lot but never finished a robot.<br /><br /.<br /><br />Welcome and thanks for reading!merlin13