The Hazards of Programming Nicely

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am returning to the modded MineCraft world where I am working on exactly what I said I wanted to move on from last week. Let’s get started.

The smeltery program I wrote for last week was nice and all, but it had a bunch of potential improvements. For one, it was blind to its environment. It could only send out pulses when it was time for the next one. Plus, with the “analogue” capabilities of the regular computers, and my previous experience with dealing with analogue redstone, I was tempted beyond my ability to resist to tear out some space around the smeltery and upgrade the hardware.

Observer blocks were capable of giving off a pulse when a basin or table was filled and quickly emptied by a hopper. There are six sides in total for the computer to work with, but the front is on display and the top of this one is occupied with another block while the tight quarters makes threat of cross wiring redstone lines very real. Given these limitations, I set about working on a new setup capable of taking advantage of  the rs.setAnalogueOutput(string side) and rs.getAnalogueInput(string side) functions.

While I was working on the new hardware, I decided to combine the programs, and add functionality so I could pour from both places at once. I set to work with three modes in mind, meant to run almost the same code at once: “Basins”, “Tables”, and “Both”. (For the aspiring coders and grammar critics, the punctuation outside the quotes is intentional; the quotes mark the beginning and end of strings, or lengths of characters (a single symbol like a letter or digit).) The code quickly became messy, and I started going into writing functions to modularize the more deeply nested segments of code. I used a little trick I learned while writing assignments in C++ where I made a comment consisting of the comment character such that it covered a line of the editor.

//////////////////////////////////////////////////////////////////////////////////////////////////////////

The section break I just put in works in C++. Unfortunately, when I tried the Lua equivalent, WordPress changed the repeated — into a single line. Anyway, the trick is that after the comment signal, the rest of it can be either an odd or even number of character repetitions, even if the first  is double. The trick helped a little, and I pushed on, working from the extremities of the code to the main loop until I realized a bit of a mistake.

My original program was designed to loop over a number of pours to a single output. I wanted the new program to handle both at once and possibly more. I was nearing completion when I when I came to halt. The main loop was incompatible with handling both outputs at once. Ouch!

I went about redesigning it in my head, but the project just kept inflating and inflating. Soon enough, it was too big without additional notes, so I just modified my old program to work with my new hardware. Funny, how an estimated one day project ended up taking half the week and it wouldn’t have worked anyway. At this point, I am content to just leave that as it is. The hardware is set up such that the computer can tell which set of outputs to trigger and which outputs are responding, but the program doesn’t use the full functionality.

/*********************************************************************************************/

Another example of my section break for C++. This one uses the long comment format. I’ve thrown together a few more programs, but nothing amazing, and nothing refined. I have noticed a consistent pattern: once I get the code working, I want to make another, better version. ‘Maybe if I just make it do this a little bit differently…’

For my automated skeleton grinder, I already have coded up the turtles to kill the skeletons. They aren’t perfect, but they sort out the unstackables by themselves. I also learned a little more about their inventory management, so I have another idea on how to make them handle better. Besides, I also want to use more turtles to move the items about better and free up the attack turtles to actually do their main job.

My goal for this week is to fully automate the farm, at least in code even if I don’t get a presentable design in order.

Final Question: Problems can usually be solved from any different number of angles. What was the last time you scrapped progress in favor of an easier approach?

Programming for a Virtual Environment

Good Morning from my Robotics Lab! This is Shadow_8472 and today, I am taking a field trip. My sister set up a modded MineCraft World, and I am into the ComputerCraft mod. Let’s get started.

ComputerCraft is a MineCraft mod that adds computers that run actual code using Lua, a scripting language. While a lot of programs are written, compiled (turned into something the target machine can run), and executed; scripting languages are more often just run off the text file as written. They will be slower, but easier to write.

ComputerCraft itself adds basic and advanced versions of both regular computers and their robot counterparts or “turtles” as well as a few other peripherals. All computers come with a Command Line Interface. Advanced computers will even let you use your mouse and show you colors while editing a program. Nevertheless, it’s the perfect mod for dealing with computers from a programmer’s point of view. In a multi-player environment, one might even get into hacking other’s networks while defending one’s own with encryption.

One mechanic within MineCraft proper I will be relying on is redstone. Think of it as a simple wire. Signal in one end,

I have dealt with ComputerCraft before. It was a few years ago, but it’s not totally new to me. Back then, I was a complete stranger to Lua and was only interested in the early game mining abilities. Other stuff was a little low level for my patience. I eventually set to modify the code for a mining turtle’s default pit digging program. In my research before reprogramming the turtle, I did not find the copy command, so I retyped the whole thing in myself before attempting the modification. Not a smart move without a second screen. But I did get the gist of the syntax of Lua and an insight into how the program was structured. It was a good way to learn the language.

In the present, I am looking to use in-game computers to manipulate the world in more ways than just mining it. I have already used a script to automate a tedious task from another mod, in this case Tinkers’ Construct, where I would otherwise have my time taken up by micromanaging the pouring of blocks and ingot casts. It provided a refresher course on programming and in Lua in particular.

I started with a description of the problem: Automatically pour from the smeltery. I formed a mental picture of how I wanted the program to do it: Send redstone pulses to the appropriate spouts. At this point, I start mapping out the logic of the system. Normally, such a stage would be done on a whiteboard or a piece of paper, but this was a small enough job, I broke good programming practice and skipped this step.

Coding the smeltry program was fairly easy. I pulled up the source code for the default mining program on my second screen and referenced it for syntax. I usually find examples a lot easier to follow than a paragraph explanation in some documentation.

What I do find helpful is bringing up the API’s (Application Programming Interface) for ComputerCraft elements I’m working with, so I can see what variables of what types the lower level functions want and in what order they want them. Think about it as tying an extra fancy knot and someone gives you a box of strings so you don’t have to make your own rope.

Debugging for the smeltery program wasn’t the smoothest. A programming practice I failed to follow was postponing the debugging until the program was fully written. I don’t like syntax errors. I don’t remember all the errors I had, but one of them stuck out as being stubborn. I eventually got it figured out and I could start debugging the logic.

The completed program has two inputs, both integers. The first is how many pulses to send, and the second is how long to wait between each pulse, as the a premature pulse can stop the flow. The final smeltery has two copies of this program, each a slightly modified to send the pulse to the correct place. Now that I think about it, I could have combined them with an in-program menu. Of course, I could always make it fancier and fancier, but it works for now, and I want to work on other things.

***

What? I underestimated the basic computer’s abilities. It CAN use analogue redstone signals. I will have to take advantage of that later on…

Final Question: Have you ever overestimated something and later took advantage of the previously overlooked abilities?

Changing an Ubuntu Interface

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am going to change the interface on my Ubuntu Machine, Derpy Chips, from Unity to… something else. Let’s get started.

From my last post, I broke from my usual methodology and gave a nano update after my final question. Unity had decided to zoom in on its interface again, and I am not a fan. Besides, having grown up on Windows, Unity wasn’t doing it for me. The tower I set up as a MineCraft server has the MATE interface and my father’s Christmas present has Cinnamon. I’ve been able to work with those. Their OS’s came with those environments. So, this week, I’m going to learn a little more about what’s available in terms of GUI’s (Graphical User Interfaces) for Ubuntu and see about altering mine.

Wikipedia is a good place to start. I won’t get any final answers there, but I’ve already done some preliminary research. Warning: Terminology Overload Incoming. I’ll try to use searchable Wikipedia page titles for terminology, but I can’t list everything. I started at Unity, read a bit about it, and browsed past GNOME, the interface Ubuntu is looking to change to as a default, to Desktop Environment and Graphical User Interface and Shell. I need to do my self-assigned reading on my terminology so I’m not misinforming you later.

***

Shell: This is typically a user interface designed as a go between the operating system and the user.

GUI: Graphical based shell.

Desktop environment: computer GUI modeled after a real desk, presenting information as if on digital paper or windows.

After looking through a few options, I am opting to try installing the Cinnamon Desktop environment on Derpy Chips. The reason is that I intend to later update to the latest LTS version coming out at the end of the month and they will have GNOME 3 as the new default environment. I don’t believe it is actually a desktop environment, and if I don’t like it, I can just go back to Cinnamon or whatever I go with now.

***

I installed Cinnamon, and it was actually almost painless. I did a quick search and fount a blog LINK. The desktop came back at a civilized resolution with respect to the different interfaces. I did forget to follow the final instruction and switch between the installed environments, but it wasn’t too hard to finish.

When I got in, it was pretty basic. It didn’t remember my lefty mouse settings, and there was no default background image. I’m not sure I like the windows, but I still need to play around with the appearance settings. At least it remembered my installed programs. I’ll spend some time moving in and possibly give a report. Just now, as I was typing the last sentence, the basic screen saver activated, a military time clock, and as I was typing this one, it started flitting about the screen. I can’t say I like that one. Just another thing to play around with I guess.

Final Question: This week I solved a problem by going for a completely different solution. Have you ever done likewise?

A return to Linux Tech Support

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am trying to install an old favorite game of mine, Sim Coaster, onto my Linux test machine, Derpy Chips. Let’s get started.

As a note, while trying to get this game to play again, I have come across documentation calling it Theme Park Inc. I believe it’s the same game except just outside the US, so in my research, I am paying attention to both titles of the name. On the other hand, this game is not Sim Theme Park.

I believe I have talked about Wine before, but since it’s been a while, Wine is a compatibility layer between Linux and programs meant for Windows; meaning when writing software for a particular OS, you can expect certain chunks of code to be there. Linux would lack any of those “libraries” of code written for Windows, but if something were there to provide the same functionality, the CPU could still run the program.

Now, this all sounds great, but due to the branching version nature of Linux, it is really hard to find the correct, decent help. You might stumble across some workable instruction set right away, or you might goof something badly by following advice meant for the next game or Linux version over.

That’s about where I am with getting Sim Coaster to run right now. WineHQ says it should install and run perfectly (all be it based on a single, old report). I have it installed, but it isn’t working. Apparently, my old favorite has a number of similar enough (and more popular) competing games from the same era that Coaster doesn’t have a dedicated support section.

In an unrelated incident, my Derpy Chips computer lived up to its name, but not the way it earned it. While getting ready to set up a modded MineCraft server for use my my family on Sabbath, the screen zoomed way in, the Unity interface’s side bar taking up a quarter of the screen. The graphical interface was useless; I ended up opening up a terminal and tried to use my Windows machine to look up a fix, the xrandr command. Nothing seemed to come of that, but I swapped around my monitors until I seemingly fixed it, but I ended up giving up in defeat and putting it on the server machine when I put the screens back to their respective computers. (Normally the Windows machine has the HDMI and a smaller screen on DVI, but Derpy Chips gets the DVI when I’m using it.)

After Sabbath, I came back to the Derpy Chips problem to unscramble it, and it was all fixed. NOTHING is more frustrating than an evasive solution that comes on its own, at least for now.

Final Question: Have you ever gotten something working on you when it shouldn’t?

***

GAAAA! Zoomed in interface is back!

Ya, I can fly.

Good Morning from my Robotics Lab! This is Shadow_8472, and today, I am reviewing my first full week with my fancy new drone. Let’s get started.

My rough learning curve went about like so:
Uncontrolled hover-bounce at ground level (Perfect for tangling the propellers)
Race car around the house
Learning trim to balance the controls
Uncontrolled elevation introduction (Perfect stage for crashing into objects and causing damage to the drone)
Uncontrolled Yaw (left/right) introduction (Perfect for disorienting you if you aren’t careful)
Teaching sister what I knew, only to feel showed up
Early use of the flip functions
Understanding of the trim controls
Hover refinement
Race drone around the house
Finer movements

Getting the second battery was a really good idea. Sure I didn’t have a second charger, but it made for a longer flight session when I just had to swap the battery out and they were both charged.

Early on, when I was still getting used to the controls, I tried dodging the drone and catching it… OUCH! The throttle wasn’t down in time. I still have the remains of a tiny blood blister on my right ring finger.

Flying the drone across the ground actually reminded me of a favorite Star Wars podracing game I used to love. Technology marches on, I guess, unless I can get it running in Wine on Linux some day.

Crashing and bending a blade does not mean a drone is unflyable. You just need to adjust the trim and keep learning on the damaged gear. My two front propellers each have nicks and a back one has a bend in the plastic.

It’s a good and fortunate thing both my batteries were discharged at one point. One of them turned up after being missing and it had a fresh puncture in it. I am thankful to God none of the animals got hurt and our house didn’t burn down, but I am still a bit emotionally charged at losing a battery. At least the event triggered me to go get a binder for some drawings I made up as part of a role play.

Nothing groundbreaking has happened since then, I continue to get better, maybe I can try out the level 2 maneuverability settings, but I haven’t given that much thought yet. I have enough control to usually land on someone’s FLAT hand if the drone is flying propellers up, but I still goof the drone into something every so often. I’ve tried interacting with the animals with it, mainly by blowing some air their way, but I don’t feel that is wise after my dog tried to catch it mid-flight. I tried to dodge, but he was faster and I had to cut the throttle.

Final Question: Ever have a side project crash one of your problems and move you to fix it? If so, what was it?