An Improvement in Photography

Over the past year, my photography has seen a dramatic improvement. I just went back to an old post of mine and realized that most of the links were broken because I had deleted them from my deviantART gallery because the pictures did not seem any good to me anymore.

I’m lazy at post processing, so I usually don’t upload a photo until a few months after it was taken; heck, there are still tons of unprocessed shots in my library that I think are worthy for uploading.

But for the finished ones, here are some I am proud of, though as /r/photocritique has shown me, they all have their flaws:

This slideshow requires JavaScript.

I usually only update my dA and Shadowness, but here they all are:
deviantART
500px
Flickr

New deviantART Photos

•October 11, 2011 • 6 Comments

Just wanted to show off some new pictures from my deviantART gallery.

Enjoy, and be sure to check our my deviantART profile!

NXC RNG: Mersenne Twister

•July 22, 2011 • 4 Comments

Here’s an example use of my implementation of the MT19937 Pseudo-Random Number Generator algorithm for NXC:

#include "MersenneTwister.h.nxc"
#include "random_ul.h.nxc"
#include "uniform_int.h.nxc"

#define MAX 10

{
MT_srand();
NumOut(0, 0, urand(MAX));
Wait(2000);
}

The repository/sources can be found here.

Once you’re done with Spiller’s post on compiling NXC code in Notepad++, you may wish to improve the look of things a bit.

NOTE: Due to Notepad++ limitations, we’re going to have to sacrifice the C language, and NXC shalt be born from its ashes. (Don’t worry: you can always use C++ as a substitute. :))

Let us begin.

Adding the .nxc File Extension

1. Open up Settings->Style Configurator...
2. Select C under Language :
3. Under User ext. :, add nxc

This straightforward, humble action should bring life to your source code.

In the same Style Configurator dialog:

1. Under Style :, select INSTRUCTION WORD
2. Under User-defined keywords, copy and paste the following:
__FLTRETVAL__ __RETURN__ __RETURNF__ __RETURNS__ __RETURNU__ __RETVAL__ __STRRETVAL__ __STRBUFFER__ __STRTMPBUFFER__ __TMPBYTE__ __TMPFLOAT__ __TMPLONG__ __TMPULONG__ __TMPWORD__ asm false mutex priority repeat start stop sub true until
3. Under Style :, select TYPE WORD
4. Under User-defined keywords, copy and paste the following:
bool byte string inline safecall task

1. Open up Settings->Preferences...
2. Click on the Backup/Auto-Completion tab
3. Under Auto-Completion, check the Enable auto-completion on each input and Function parameters hint on input checkboxes
4. Select Function completion
5. You may also wish to change it to “From 3 th character”, or something like that.

Customizing Function Auto-Completion for NXC

UPDATE: I haven’t tried it yet, but bungeshea has made a new version that uses features introduced in Notepad++ 6.2.

This part is not for the faint-hearted. Venture on if you dare. (Actually, it’s not that complicated.)

1. Download the NXC API to Notepad++ XML Converter binaries here. (Or compile them from source, if you wish.)
2. Drag the %ProgramFiles%\BricxCC\Default\nxc_api.txt to NXC API to Notepad++ XML.exe.
3. Rename the newly generated nxc.xml file to c.xml.
4. Move c.xml to %ProgramFiles%\Notepad++\plugins\APIs\.

That’s it!

Plugins

NppAutoIndent

This gives you a “smart indentation” feature. I find it pretty useful.

1. Open up Plugins->Plugin Manager->Show Plugin Manager
2. Under the Available tab, check the NppAutoIndent checkbox
3. Click Install
2. Enable Plugins->NppAutoIndent->Smart Indent

Creating and Editing RIC Files

•May 27, 2011 • 2 Comments

There are a few tools available to edit RIC files. This post will describe their strengths and weaknesses. (If you know any others, please leave a comment.)

nxtRICedit

by Andreas Dreier

• Free
• Windows only
• Easy to use
• Supports NBC/NXC Enhanced Firmware exclusive features

nxtRICeditV2

by Andreas Dreier

• Free
• Windows only
• Supports NBC/NXC Enhanced Firmware exclusive features
• Bugs in GUI
• Window not resizable
• 1280×780 resolution required

RICcreator

by Sebastian Wahl (Spiller)

• Free and Open-source
• Written in C++, Qt
• Cross Platform (Windows, Mac, Linux)
• Supports NBC/NXC Enhanced Firmware exclusive features
• Easier creation of RIC fonts
• Powerful ability to import Image Files (PNGs)
• Good GUI

RICScript

• Free and Open-source
• Text based editor (Requires BricxCC or NBC Compiler)
• File type before compilation: .rs
• Cross Platform (Windows, Mac, Linux)
• Supports NBC/NXC Enhanced Firmware exclusive features

Recommendations

Here’s what I recommend.

Beginners: Use nxtRICedit.
Advanced users: Use nxtRICeditV2, as RICcreator is still under development. Once it’s stable, you should use RICcreator. UPDATE: Use RICcreator; it’s pretty awesome now.

nxtRICeditV3 may or may not come out soon. It is intended to address the bugs in nxtRICeditV2. When it comes out, you can get rid of nxtRICeditV2. (If you decide not to use the awesome RICcreator, that is!)

Basic types for NXC Memory Manager

Well, so far I’ve got a few of the basic types for Memory Manager tested and working. (BYTE, CHAR, INT, UINT.) A few more should be implemented soon. (LONG, ULONG, FLOAT.)

After that, I’ll need [someone] to test MM_convert(); this will allow you to convert between different types:

MM_ID idf = MM_new(MM_ID_TYPE_FLOAT);
MM_ID idl = MM_convert(idf, MM_ID_TYPE_LONG, false);


(The last false parameter specifies that you don’t want idf‘s memory to be automatically deleted.)

Another thing I’m working on is MM_op(). It will allow you to execute operations:

// int a, b;
MM_ID a = MM_new(MM_ID_TYPE_INT);
MM_ID b = MM_new(MM_ID_TYPE_INT);

// a = 4; b = 2;
MM_set_INT(a, 4);
MM_set_INT(b, 2);

// answer = a + b;


Sure, you can always MM_get() them, and manually execute the operations, but that’s no fun! 🙂

Actually, all of this should be hidden behind a “parser” (it’s more like an interpreter), so you won’t have to worry about it at all; you’ll simply call MM_parse() to do all the work for you. You’ll just need to input a string with the code into the function. This is what I’m going for:

MM_parse(" \
long a = 2; \
double pi = 3.14; \
double d = a * pi;");

float diameter = MM_parse_get_FLOAT("d");

NumOut(0, 0, diameter, 0);


As you can see, all the type conversions like long to double are handled “implicitly” (although I’ll add explicit functionality too, of course). All the memory allocation/operations/etc are handled for you, as if you were programming in NXC… inside NXC. You’ll be able to integrate your code into itself (does that make any sense?). I may also add support for a compiler directive (MM_PARSE_SYSTEM) which will allow you to execute “system commands” like NumOut() inside the parser.

If you’re worried about all that typing, you can always use #defines to make the function names shorter:

#define p(str) MM_parse(str)
#define pgfloat(str) MM_parse_get_float(str)

p(" \
long a = 2; \
double pi = 3.14; \
double d = a * pi;");

float diameter = pgfloat("d");

NumOut(0, 0, diameter, 0);


I could use some help in testing. (I don’t have access to a NXT most of the time.) I’ll post the files to test on this Mindboards thread.

Beginning Work on NXC Memory Manager

•March 18, 2011 • 3 Comments

If you haven’t heard already, I’ve begun work on a “Memory Manager”.

What it does

Using my library (libraries, actually), you’ll be able to:
[Please insert “pseudo-” in front of all the list items.]

• Create variables (bools, [unsigned] chars, [unsigned] ints, [unsigned] longs, floats, doubles, strings, and arrays of those types, too)
• Set their values (working on it; support for different ops is being added)
• Pointers! (And pointers to pointers, or pointers to pointers to pointers, or pointers to pointers to pointers to pointers, or…)
• Use “hash tables” (working on it)
• Parsers of [obfuscated] expressions (… guess; yeah, you’re right: I need to finish the hash stuff first)
• “Dynamic” memory management
• Dynamic typing (if you’re insane enough to want this), and duck typing (I just wrote this down for kicks, actually; quack quack)
• And definitely use super advanced kung-fu fighting robot functions

Example code

By “pseudo”, I mean you won’t be able to do this:

int lol = 42;
int *pi = lol;
NumOut(0, 0, *pi, 0);

But we will have something similar to this:

MM_ID lol = MM_new(MM_ID_TYPE_INT);
// prototype: MM_ID MM_new(MM_ID_TYPE type = MM_ID_TYPE_BYTE, unsigned long len = 1);

MM_mov_INT(lol, 42);
// or use MM_set_INT(lol, 42);

MM_ID pi = lol;

NumOut(0, 0, MM_get_INT(pi), 0);

It’d look a lot nicer if NXC itself supported function overloading. >_> 😀 Assuming it did, here’s the new version:

MM_ID lol = MM_new(MM_ID_TYPE_INT);
MM_mov(lol, 42);
MM_ID pi = lol;
NumOut(0, 0, MM_get(pi), 0);

No more _INTs!

Or, if you take my “parser” into account, something similar to this:

P_parse("int lol = 42;");
string pi = "lol";
NumOut(0, 0, P_get_INT(pi), 0);

How to contribute

If you’re willing to help, you can become a tester. I don’t have a NXT with me all the time, so I post things for people to test at the Memory Manager thread on the Mindboards Forums.

Also, I’ve set up a Mercurial repository, if you want to check out my progress.

Motor Speed vs. Motor Power

•February 9, 2011 • 10 Comments

Polled at a Motor Power Output (%) every 5% increase, over a motor rotation of 720 degrees each. Motor Rotation Speed vs Motor Power Output (%) for NBC/NXC Firmware 1.28. As you can see, it's a pretty linear.

I was interested in how fast the motors would spin (in the air for the first tests, to not let gravity/load/friction/etc affect the results) depending on what I set pwr in the NXC function OnFwd(outputs, pwr).

I wrote a program (download here) which logged the time it took to spin the motor at 720 degrees (in one experiment), and with a starting pwr value of 5, increasing by 5, until it reached 100. It was tested on the NBC/NXC Firmware 1.28.

It seemed to be linear, and I did a little “analysis” (if you can call it that), and came up with the graph on the right, which represents the ratio between Speed and Power. This ratio is about 7:1.

Next, I tried it with the robot on the ground. The results were pretty much the same (linear), as you can see in the image to the bottom left. Of course, it slowed down a bit, as can be expected.

I still haven’t figured out how this is useful, but if you can suggest reasons for why I haven’t wasted my time (which I actually like doing, believe it or not), please tell me in the comments. Now I’m adding meaningless text just to fill this line, so my blog post looks good. 🙂

Set Firefox [4] Default Search Engine in URL Box

•January 25, 2011 • 9 Comments

This post will show how to make the Firefox [4 Beta 8] URL box (which is the left one, by default; and it’s different from the search box) default to Google when something other than an URL is entered. (Just like Chrome’s omnibox.) It currently goes to Yahoo! For example, if you type, “hello world“, you want it to search for “hello world” (in Google). But it searches this in Yahoo! instead! Fortunately, there’s a way to change it to Google. (URLs like muntoo.wordpress.com will not be affected.)

1. First, type in “about:config” into the url box, and click on “I’ll be careful, I promise!“:

2. Under Filter, type in “http://search.yahoo.com/search?p=“:

3. Edit the value of keyword.URL by double clicking it (or right click->Modify) and change it to “http://www.google.com/search?q=“:

4. Do the same with browser.bdtoolbar.orig_keyword_url:

5. And you’re done! Test by typing “the answer to life the universe and everything” into the url box.

Bezier Curves On The NXT

•January 13, 2011 • 5 Comments

Bezier Curve Speed Test for a 4th Degree Bezier Curve. At a resolution of 50, each new render takes 286.5 ms, or about a third of a second.

As some of you from NXTasy may remember, I was working on a Bezier Curve implementation for the NXT in NXC. (I was also competing with Spiller for rendering speed; his code is in BezierCurve.zip\BezierComparison\Bezier_curves2\Bézier_curves2.nxc) I’ve managed to render the curve in the picture above in 286.5 ms. And that’s a 4th degree curve (3 control points and 2 end points) with 52 different points along the curve calculated and interpolated to give a “high resolution” output.

To do this, I added a bunch of my own optimizations and tried to avoid floating-point operations where possible. Then, using Spiller’s idea that:

$\mathbf{B}(t) = \displaystyle\sum_{i=0}^n {n\choose i}(1-t)^{n-i}t^i\mathbf{P}_i$

Can be converted to:

$\displaystyle \mathbf{C}_i = {n\choose i} \mathbf{P}_i \\ \mathbf{B}(t) = \displaystyle\sum_{i=0}^n (1-t)^{n-i}t^i \mathbf{C}_i$

I was able to speed up my drawing routines by up to 200%! (On the GeneralBezierCurve2DOut() drawing routine.)

NOTE: $n$ is the degree of the curve. $\mathbf{B}(t)$ is the Bezier Curve parametric function. $\mathbf{P}$ represent the control points. $\mathbf{C}$ and $i$ are temporary variables.
NOTE 2: Math geeks, sorry about the “while” notation. If you have any ideas in which I can use pure mathematical notation without resorting to C, please notify me by leaving a comment.

As well as the demos, I’ve included an entire library (BezierCurve.zip\BezierCurve\v0_3\BezierCurve_v0_3.h.nxc). It can:

• Draw curves on the screen using BezierCurve2DOut().
• Draw different shapes using the ShapeType parameter! For example, you can interpolate the points using Lines, make the curve thicker by using [Filled/Clear/etc] Circles/Ellipses, or make “calligraphy” effects using [Filled/Clear/etc] Rectangles.
• Determine the length of the Bezier curve using GeneralBezierCurve2D_Length_LocationType().
• Draw/connect points in an array onto the screen using LocationType_PointsOut(). (And specify the shape too, of course.)
• Pre-calculate Bezier curves and store their values in an array to increase program performance using BezierCurve2D_GetPoints_LocationType().
• And more!

It is possible that it requires the Enhanced NBC/NXC firmware. That is available here. [LINK]

Here’s a video of the demo/speed test programs in action: