Jump to content

Controlling trains with an iPhone / iPod Touch


serenityFan

Recommended Posts

Also, I generally just want to get to know Objective C and Cocoa and program for iPhone / iPod Touch. I think I have some interesting ideas with regards to that, and have already started working on a prototype app.

 

Wait a sec, are you saying we are going to see an iphone app that can control our trains? Made by you? Cool .....  :grin :grin

Link to comment
Martijn Meerts

Also, I generally just want to get to know Objective C and Cocoa and program for iPhone / iPod Touch. I think I have some interesting ideas with regards to that, and have already started working on a prototype app.

 

Wait a sec, are you saying we are going to see an iphone app that can control our trains? Made by you? Cool .....  :grin :grin

 

Possibly, but it won't be as easy as installing the app and running. There'll need to be a program on a computer which the layout is connected to, which sends on the commands received from the iphone.

 

I have a bunch of idea, but I don't really want to throw them out in the open just yet. But if anyone is interested, feel free to send me a PM for some more detailed discussions ;)

 

 

There is actually an app already to control trains, but you need either a Marklin Central Station or the ESU ECoS.

Link to comment
Martijn Meerts

Split this topic from the original one so we can talk a bit about it...

 

I've been progressing a bit faster than I thought I would, I don't have anything that can actually control a train yet, but the iPhone / iPod Touch bit is coming along nicely.

 

 

The initial idea was to build a Mac OS X app that would combine a model train database, decoder programmer, and manual throttle control (so, for now at least, no blocks, occupancy detection, signals, turnouts etc.) I actually started working on this a while ago, and have 1 of the more challenging technical bits working. I can actually send commands to the command station via the interface, and the trains will respond to them. Since my Japanese trains use a Lenz LI-USB interface, that's so far the only one that works. I also still have the commands hard coded in the program, so it's very limited, but the connection is there ;)

 

Looking a bit further at interface elements and database storage and the likes, I quickly found out that the OS X API has an insane amount of frameworks, and each of them have an insane amount of functionality. So, I decided to first look at iPhone development, because obviously it's much more limited.

 

On the iPhone, I've managed to clear a few initial technical hurdles. I can test the availability of WiFi, and I've managed to set up a basic database so that trains can be stored locally on the iPhone.

 

To control trains using the iPhone app, it requires a pairing with the computer that the interface is connected to. So, the OS X app will also include a server that the iPhone app can connect to. For those who have an iPhone / iPod Touch, install Apple's "Remote" app, which allows you to control your iTunes library via the iPhone. That uses the same mechanism I was thinking of using. I've come a ways there as well, I can browse the WiFi network for machines that are running a certain service, and then connect to that machine.

 

 

My main issue right now is actually the interface. While it's easy enough to create an interface to pick a train to control, I'm really rather stuck with how the actual "throttle" should look. I also have only a very basic idea of how I want the OS X app to look. I may be able to design webpages, but application interfaces is definitely not my thing =)

 

Ideas and concept sketches would be greatly appreciated ;)

Link to comment
alpineaustralia

You lost me just after "Split this topic from the original one so we can talk a bit about it..."

Sounds exciting mate.

At thisstage I have just recived my first ipod nano and am coming to grips with it.

Link to comment

Martijn,

 

I'm about to drop the dough for an Android phone. Would be interesting to do a tandem iPhone/Android release :D I would be willing to chip in time and effort on that!

Link to comment
Martijn Meerts

Martijn,

 

I'm about to drop the dough for an Android phone. Would be interesting to do a tandem iPhone/Android release :D I would be willing to chip in time and effort on that!

 

It should be possible to hook up an Android phone, as long as the Android phone sends and receives the same data from the "server" as the iPhone app.

 

Networking on the iPhone (and OS X for that matter) isn't all that easy. Detecting servers/clients works fine, you can just use Bonjour for that. However, creating sockets and sending/receiving info tends to require some low-level C, something I'm not comfortable with.

 

I'm probably going to use http://bitbucket.org/snej/mynetwork/wiki/Home as the basis of pairing the iPhone app and OS X app.

 

It would of course also be possible to write a windows server app, but we'd need someone with windows programming knowledge =)

 

 

 

I think we should discard the whole DCC thing and just take advantage of the RC technology.

 

Hmm.. Not sure I can see a lot of advantages of RC compared to DCC, especially not once you start with computer control and automating layouts ;)

Link to comment

Interesting thread.

 

Shouldn't the throttle be a "horizontal slide buton"? You could have it graduated to have an idea of the "speed" (from 0 to 100 in percentage) and a window displaying the precise value in digital number.

Link to comment
Martijn Meerts

I'm pretty sure that a slider of sorts is the best to select the speed. Not sure if horizontal or vertical is better from a usability stand point. A vertical one can be bigger, which means better control.

 

But that's only the speed of the train, the "throttle" (maybe it's better to call it controller really) also needs buttons for functions and indicators for direction of travel and the likes. The question then is if it would be better to simulate a "real" controller, or make it much more abstract with standardized buttons etc.

 

Apple's Human Interface Guidelines don't help much here, since they state that if you make a virtual version of a real device, it might be best to make it look like the real device, so that people will instantly know how to use it. On the other hand, it also states you shouldn't make custom buttons and controls unless it's really necessary =)

Link to comment

My advice is: it must be easy to use and handle. That's the key feature and the design must reflect it.

 

As for the size and direction of the controller, with the Iphone the screen can rotate so you can use this feature at your advantage by using the horizontal control in the greater dimension. You will also have to test (or ask around) to see if it's easier to move your hand on the horizontal or in the vertical. For me that's clear, it's the horizon.

Link to comment

So basically you would need to be able to control your layout from a computer, and then the iphone simply sends instructions to the computer which controls the layout? I better learn how to do the first part first  :grin :grin

 

Martjin, what about available modules, like JRMI? Would that be incompatible with what you are building?

Link to comment
Martijn Meerts

So basically you would need to be able to control your layout from a computer, and then the iphone simply sends instructions to the computer which controls the layout? I better learn how to do the first part first  :grin :grin

 

Martjin, what about available modules, like JRMI? Would that be incompatible with what you are building?

 

 

If you have a Marklin CS / CS2 or an ESU ECoS, you would be able to skip the computer part, and have the iPhone send commands directly to the command station. The reason for that is that those command stations have a network connection. Pretty much all other command stations are either USB or good 'ol RS232.

 

Of course, the advantage of requiring a computer, is that it's possible to support all digital systems, even those not released yet.

 

 

It would be possible to use JRMI, and build an iPhone add-on on top of that, but I don't know Java at all, and I don't feel like learning both Java and Objective-C (Objective-C I need for iPhone development)

Link to comment
Martijn Meerts

Oooh, ooh, I have a shuffle, I can't wait to see how my trains would run with it.

 

...tumbleweeds roll on by.

 

They won't because you can't install apps on the shuffle ;)

Link to comment

Martijn,

 

I find this thread very intriguing! would be very cool controller. what about just networking into a netbook running jrmi and sending jrmi commands (sure they must have some sort of external communication protocol) and letting it do the running/control of the dcc stuff? would mean you just have to learn how to tell jrmi to accelerate, break, turn on/off what decoder and then let it do the actual dcc work/communication.

 

rub maybe having a tcpip protocol with jrmi to talk to it, the world is slowly going that way. most of the equipment though that is not native tcpip is using telnet to make the bridge and thats a royal pain in the patute to keep open all the time!

 

im just starting to really look at the touch for exhibit purposes, thing have finally gotten to a really great nexus of functionality, design, software apis, cost, etc to make it a very viable option for visitor use!

 

cheers

 

jeff

Link to comment

I'm also starting to toy with the idea of designing a LocoNet/Lenz XPressNet -> TCP/IP device using ARduino. Would allow the command station to be connected directly to your LAN (or the internet!), again bypassing the need for an intermediary computer just to control a train. That could be fun.

Link to comment
Martijn Meerts

Martijn,

 

I find this thread very intriguing! would be very cool controller. what about just networking into a netbook running jrmi and sending jrmi commands (sure they must have some sort of external communication protocol) and letting it do the running/control of the dcc stuff? would mean you just have to learn how to tell jrmi to accelerate, break, turn on/off what decoder and then let it do the actual dcc work/communication.

 

That would still require extensive Java knowledge, since I don't think JRMI accepts bi-directional connections from external devices over wifi. I also have no idea how hard that is to implement in JRMI. Don might be able to say more about this, I believe he knows a bit of Java ;)

 

 

Another reason I wanted to start from scratch, is that I have a couple of ideas floating around, which would be much easier when having a custom OS X app compared to modifying / adding to JRMI. One of those things (which might be interesting for you with regards to exhibitions), is to allow the OS X app to limit which train(s) are possible to be controlled with each paired iPhone / iPod Touch, and limit certain settings (max speed etc.) That basically means you could have an iPod Touch available for visitors, who can then control a train on the layout. Pretty sure kids would love to be able to control Doraemon or Dr. Yellow =)

 

Another idea is to have the OS X app feed data to an iPod touch which you have mounted somewhere near a large station. Based on some block detection system, the OS X app would know which trains are about to enter the station, and can tell the iPod Touch to display which train will arrive on which track etc.

Link to comment

Martijn,

 

sorry i have not take the time to really look into the jrmi system. was hoping that they were making a very open system to allow easy communication with external elements like this. i too have not taken the time to really dive deeply into java, one of those things that you have to have a big need to feed the learning curve!

 

these would be wonderful for show layouts for both member and visitor control of trains. dcc makes it perfect to limit speeds and actions so visitors cant do horrible things. we have been looking at dcc to make a visitor throttle and just wire the decoder to the tracks so we can use non dcc trains, but still limit the throttle speeds and acel and decel.

 

only problem with touches at a train show with visitor use is they could walk off easily!

 

btw, im actually looking into the use of the touchs in museum exhibits to deliver content in interesting and different ways. it allows you to keep stuff up on the walls to the big picture and getting folks interested, then followup with more detailed and varied presentations on the touch that folks can dive into (and down in multiple levels) depending upon what they are most interested in. this is traditionally done in computer kiosks, but those are physically imposing, expensive and hard to design into your exhibit flow. for one kiosk you could buy like 25 touchs, so lots more folks could interact with the at once and at whatever place and time in the space they want to. main downside is that they can be isolating, especially if you do audio, so this is the design challenge to see if it can be done w/o isolating visitors from each other and maybe even figure out ways of using it to get visitors to interact with each other in novel ways in the exhibit space.

 

cheers

 

jeff

Link to comment
Martijn Meerts

I haven't looked much into JRMI either to be honest, I only use if for decoder programming. For anything else I just think it's too confusing ;)

 

As for walking of with an iPod Touch, that could be a problem of course. However, there are 2 main ways this could be solved. If you supply your own iPod Touch, you could basically hook up some security wire to it. It'll make things a little more limiting, but it's better than having to buy new iPods for each show. Another option is to allow visitors who have their own iPods to pair their iPod with the OS X app. As the admin, you could then specify which train that iPod gets access to. Of course, they'd have to install the app, but the idea is to make it available for free anyway ;)

 

 

What could be interesting for a museum would be to use a form of Augmented Reality. Unfortunately, it requires a camera, so it won't work with the current iPod Touches, but it would allow you to overlay an interface onto the camera image. If you could somehow make it so the iPod would recognize the exhibition pieces, you could then tap the piece on the screen of the iPod, and more info would pop up.

 

 

This is a good example of recognizing and tracking markers. It's all a bit slow, but it's still early development ;)

Link to comment
Martijn Meerts

Here's a screen of what I've been able to do so far. All these screenshots are taken from an actual device (as I'm a registered iPhone developer, I can test my stuff on a device, not just on the simulator =))

 

Left to right, top to bottom:

 

1 - Initial screen, it checks to see if WiFi is available (required to connect to the OS X app, iPhone app still usable as database when WiFi is off)

2 - List of trains, showing "name" and "description", still need to add thumbnail image. This data is taken from a database, and it not static.

3 - Select a train and...

4 - ... you get the "throttle view", although, there's not much of a throttle there yet ;)

 

5 - Tapping on the "+" button will allow you to add a new train. Tap a field and...

6 - ... the keyboard pops up. Tapping cancel will cancel input, tapping save will save a new entry in the database.

7 - Tapping on the trash can button allows you to delete trains. Tap on the red circle button and...

8 - ... you'll get a confirmation to delete the train. Tap the "delete" button and the train is gone. Tapping "done" will leave delete mode.

 

9 - Searching is also possible

10 - It'll search on both train names...

11 - ... as well as train descriptions.

 

Clicking on the blue circular button should bring you to a detail view, but I haven't started on that yet.

iPhone_app.jpg

Link to comment
Martijn Meerts

Quick update.. Haven't been able to do much due to work...

 

 

I've managed to make a WiFi connection between an iPhone app and an OS X app, which means I can send data from the iPhone app to the OS X app, which can then get translate into something that the digital interface understands.

 

So, for example, in the iPhone app I'm controlling a locomotive with DCC address 3. I can move a speed slider which fires some code in the iPhone app which reads the value. I then create a bit of data that includes the locomotive address and the new speed step. That data gets sent to the OS X application over WiFi, where it'll be translated into the hex values that the Lenz interface needs. And, if all goes well, the locomotive will change its speed =)

 

 

In short, I have all the core functionality functioning now, I "just" need to build the necessary components around it =)

Link to comment

Martijn,

 

Hey congrats, i know that feeling when you complete that control chain from interface to device, its a great feeling as then you know you can do what you need to! I remember trying to figure out a control table/matrix in hex for a sony projector that had everything else written in japanese (tech docs had not yet been translated on the new model). lots of poking and fiddling, but that wonderful feeling when you get the rosetta stone and you push the button and the action happens!

 

cheers

 

jeff

Link to comment
Martijn Meerts

Yeah.. iPhone development actually makes that easy on you.. Not specifically the part where you get the core to work, but writing something for the iPhone, and then seeing it work on the actual device itself rather than a simulator is really stimulating.. That definately helped me with getting as far as I have so far.

 

Also, the Objective C syntax is starting to become familiar, and I can understand sample code much better by now, so it's all positive so far =)

Link to comment

Im envious! would love to work on some iphone apps, but C is just way, way too much pain with my dyslexia. just takes all the fun out of it and puts the frustration way too high...

 

keep playing, love to see where this all leads!

 

cheers,

 

jeff

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...