Thursday, December 3, 2015

ANTLR quickstart

He's a resource I wrote for those of you wanted to get started with ANTLR, but cut through the BS red tape and get straight to writing grammars! Here it is:

I spent a lot of time trying to get ANTLR in usable shape, and I found the documentation dreadful. So allow me to lay out a much easier alternative to using ANTLR right out of the box, that doesn't require finnicking with system variables that never work.

This may not be the most "flexible" route, but is certainly the quickest one in my experience. The instructions are usable in both UNIX and Windows.



  1. Download the java jdk.After you have it installed you *should* be able to invoke the "java" command from your command prompt. test it using "java -version". If you get some kind of output from that, then great!
  2. Download the ANTLR complete jar.There are two antlr sites in an attempt to separate ANTLR3 from ANTLR4.
    If you want ANTLR4, go to antlr.org
    If you want ANTLR3, go to antlr3.org
    In either case, download the complete jar to a location you wouldn't mind using it.
  3. Test installationIn your command prompt move to the directory that contains the complete jar.
    try the command

    java -cp antlr-x.y.z-complete.jar org.antlr.Tool

    in ANTLR3, or in ANTLR4,

    java -cp antlr-x.y.z-complete.jar org.antlr.v4.Tool

    This command should work, and return options for ANTLR.
    The cp argument means you can you specify CLASSPATH within the command, removing
    the additional step of fooling around with system variables.

  4. Test output
    Use the included "Exp.g" grammar taken from a stackoverflow question and run the following command in ANTLR3

    java -cp antlr-x.y.z-complete.jar org.antlr.Tool Exp.g

    or in ANTLR4

    java -cp antlr-x.y.z-complete.jar org.antlr.v4.Tool Exp.g

    If you're using your own grammar, make sure that the filename matches the first line, e.g. grammar css = css.g

  5. Test different target.In your grammar, add the line

    options{language = C;}

    where "C" is whatever target language you'd want. I'm typically concerned with C or C++
    output, so I use "C" or "Cpp", though ANTLR4 doesn't target C or CPP.
    Run the same command again, and check that it ran correctly and output matches the desired filetype.

  6. Design your grammar
    Congratulations. If the step before worked, than you have everything you need to start doing *actual work* with ANTLR! I hope this was helpful in getting you started, and not hung up on installing stuff. 

Edit:
I found myself also need to check out antlrworks to see how my grammar is structured. As of 1.5.2, try

java -jar antlrworks-1.5.2-complete.jar org.antlr.Tool <grammar.g>


"Installing things is the hardest part of programming."

Monday, November 30, 2015

Code for WRT-T1 added on Github!

Hey everyone,

the source code for the WRT-T1, along with two tests I used during development are now available on my Github.

Sunday, November 22, 2015

"Artificial Intelligence: The Very Idea" by John Haugeland

I'm not a philosopher, but I'd like to think of myself as a deep thinker when it comes to the topics I love like robotics, computing and artificial intelligence. I've wanted to read more literature about these topics in my free time, so I started by going through my backlog of books I picked up from half-price books. One of them was a used copy of John Haugeland's "Artificial Intelligence: The Very Idea". As I may have hinted, this is a far more philosophic book that I'm used to reading, but I highly recommend it whether you're a student of computer science or of philosophy. While I was familiar with many of the computer science topics (like Turing's work and computer architecture), many of the philosophic approaches to AI problems were really refreshing and exciting. Some would complain that the book is a little dated (published in 85), but I would argue that the concepts are just as relevant today. To dismiss the idea that AI could afford to more closely resemble some of the finer parts of the human consciousness would be very short-sighted, so even if the idea seems silly the book is far too informative to dismiss without at least hearing how AI could stand to benefit from some of these features, and what they mean to our understanding of intelligence. On that topic, the book is equally interesting as an exploration of what makes human intelligence. You'll leave with an appreciation for a lot the innate "talents" the human brain can accomplish, and wondering if they can translated as automatic formal systems. 5/5

http://www.amazon.com/Artificial-Intelligence-The-Very-Idea/dp/0262580950

Tuesday, November 17, 2015

WRT-T1: Wireless Raspberry Pi Tank

After several bouts with circuits, CMake, and the Raspberry Pi's weak PWM game, I've finally finished my first revision of my wireless Raspberry Pi tank, my first first, albeit boring solo venture into teleoperated robotics. :)





The first challenge was framing the input and output. I chose to make the input a wii remote intitially because I wanted to use a game controller, but a simple one. When I was younger and the wii was still a new console, I remember being amazed at a college kid who powered most of his dorm through the wii remote, so learning wii remote input has always been a desire of mine. Not to mention the unit is compact, wireless, and has many different peripherals. I went with this library called WiiC, which functioned quite nicely. As you can see from the demonstration below, I paired wiimote input with LEDs on the Rasberry Pi's GPIO using WiringPi:



Next came working with the motor output. I chose to build my own motor driver circuit (for some reason) built off of a h-bridge IC. I first prototyped a version on a breadboard and tested it with the Arduino Uno. Then, I got out my soldering iron and built it onto soldered micro breadboard from Sparkfun. Below you can see the fritzing diagram, and how it interfaces on the Raspberry Pi. Each motor has two logic pins and a speed pin. I also have a second LED to act as a signifier that the wiimote is connected.


The last part was writing and testing a state machine for driving the motors. I could have conceded to doing all digital tank controls wherein you can only drive OR turn, but I simply had to have some more natural turning, so I then began fussing with using PWM (pulse-width modulation) on Raspberry Pi. As it turns out, the Pi only has one native PWM, so in order to go beyond that, you need to force wiringPi to create a "simulated" PWM using the processor's clock, which is a bit of a pain. Thankfully I managed to get it working though. As it stands I still need to back off the wheel that's being turned around.

The last steps that remained where changing the raspbian OS to boot that program on startup, with log-in and use an external power source. I decided to use one of the USB charging sticks that I got from an underwhelming career fair I attended in college that made me depressed. But hey, now it powers my sick robot!

Anyways, I have plans to return to this project and apply a number of upgrades, including camera and networking controls, and some kind of armament.


Thursday, November 12, 2015

November Update



Does Jacob still do stuff?


Why yes! I sure do. It's not all once, and it's not always to completion, but I sure do things! I was thinking deeply today about things like spoilers, datamining, and reveals. I was wondering if I should adopt a sort of "showroom floor" attitude towards my accomplishments and only post them on completion, but I feel that undermines all the work that goes on beforehand! There's already so many people suffering from technological illiteracy that feel like things just come into being after someone has an idea, but really there is and always will be a lot of hard work between those two points. And I feel it's time that I reveled in that time a bit more. I feel like there's a lot of pressure around to get in, get working, and get done, but the truth is this is what I do and I love it! So what if I take a break? I'm still contributing to a wide-base of knowledge I can pick back up at any point. That's how the brain works, and I love it!

That being said, I figured I would make a few posts about the various things I've been working on. None of them are quite at the level of the showroom floor, but that's not all there is to tech! I've been reading a fascinating book, learning to 3d print, and fussing with my new smartphone. The game is a lot different since I've graduated college, and for the time-being, I really enjoy it! Anyways, I'll be sure to post that content along with the other life-updatey things I've been doing. I'd say I have about five posts of content, and I'll try to get them out on a soonish basis. :D

Saturday, August 29, 2015

Research and Implementation Strategies

In breaking down research of larger topics, I've found that it's been useful (for me) to place a higher emphasis on reading than swinging wildly at application. I'm sure anyone interested in Computer Science understands the sometimes overwhelming pressure to create and be 'deliverable', so much so that some discard reading altogether. However, I've found that by pacing myself and spending "loose time" reading, I'm further solidifying my understanding and setting myself up for success when it comes time to begin implementation.

Another I have chose to do this is I have a bad habit of picking up a lot of books when I'm in "The zone". I remember spending time in professors' offices at awe at the large collection of books and wondering how many they had read cover to cover, how many were gifts, how many are only reference, and etc. I want to do my best to make sure that any book on my shelf I've at least read through a couple of chapters in. It can be easy when you're concerned with output to be a bit on the impatient side with books, but the fact of the matter is that you're overlooking the opportunity to gain a better, passive understanding of the material at hand.

My present example would be my study of MP3 files. Amazing stuff really. A form of compression based human psychoacoustics. However, I wouldn't have been able to reap all the fascinating information I've learned so far if I hadn't spent the time throughout reading about it. Instead I'd just be staring down the frame header documentation, wondering what each component meant, and desperately googling for every answer. I say that, because that's where I was. Staring at each individual bit, unsure of what many of them were for... but the important part is that I encountered them casually in my reading, and coming back, the whole structure has come together for me. Now it's just a matter of doing more reading into encoding and decoding, and how I can go about that.

My big idea is to spend most of the week --when my dedicated programming time is sparse-- to reading, and then use part of my weekend block to execute a small, perhaps unrelated bit of programming. For example tomorrow I'll either be looking at a 6502 assembly application or coding through a neural network in C++. I suppose it's whatever I feel like!

I'll be sure to post more about what I've learned, I just thought this entry may be useful for those who want to learn but don't have a lot of consistent time on their hands! Let me know your study strategies as well.

Thursday, August 27, 2015

The CS bucket list

As you may have seen in "My Career and My Ambition, pt. 1",  I've really enjoyed the opportunity at my work to investigate things on a deep level, such as how encodings affect the size of data as well as what characters are supported. It's got me asking a lot of questions about what the data around every day really is, on a fundamental level. How many people, technologically/musically literate or not, understand how MP3 files are structured? I don't know the answer to that question, but I would like to be one of those who does understand. So I decided to create a list of small programs I could create to systematically acquire this kind of information, a sort of "CS bucket list" (mediocre title definite tentative). Here are some of the things I'd be interested in studying:

  • Raw MP3 processing
  • Raw image processing
  • QR code generation
  • Creating an Assembly script
  • Neural Network applications 
  • File Compression
  • Live sensing
 So, these kind of applications will be a lot of the content of my future posts-- and in no particular order. I've already got a foot in the door studying 6502 and other flavors of assembly through tutorials and TIS-100. This will just be something in my free time too, so don't expect any kind of schedule. I'll gradually update on my progress from time to time.