This blog is based on an email exchange, discussing this topic and edited portion is given below:
First, the architecture. There are Features, each having multiple “data tags”. Each Feature is of type ‘contr ol’ or ‘resource’ and hence all its data tags are also of the same type. One ore more features form together a “component”. Currently, there is a limitation that all features within a component have to be of the same type (control or resource). In addition, the component names are fixed – “control”, “control2″, “control3″ (all are type “control”), and “resource”, “resource2″, “resource3″ (type ‘resource’) and so on.
When any data comes for component, say ‘control’, it is directed to ‘resource’ and vice-versa. Similarly data from ‘control2′ is sent to ‘resource2′ and so on. This is hard mapping. I could have created another configuration mapping and let the admin configure it, but there were already two more mappings – and I did not want to complicate things further.(Update: This is however implemented now, an additional Routing Controls that allows the admin to route data from any component to any component)
A hardware device, such as RobotClient or Arduino, identifies itself as the component name (such as ‘control’, ‘resource’, ‘control2′) to the server, while connecting using the API. You might have noticed that, while updating arduino text “PUT /api/Toronto3.control” – and that key “control” in that identifies it as component name “control”. This would tell the server, it is coming from ‘control’ named component and it knows what features are configured in this, and what tags to expect, what data massaging needs to be done and where to redirect the data. etc.
Also, other than some minor details (which I listed in earlier mail and produced below), the server does not “semantically” differentiate between control/resource data tags. The only thing it bothers about is which data tag of ‘control’ should be mapped (sent) to which data tag of ‘resource’. The actual differences (three golden differences) are:
- We check for the readiness of the ‘resource’, before ‘control’ can send data and allow only one control to access a ‘resource’ at a given time (but this does not make sense for sensor data, which has ‘input’ direction).
- All ‘resource’ data are candidates for historic storage – while it is not currently for ‘control’ data.
- What you said about last reading to retrieve is true for any ‘resource data (whether that data is of direction “output” — such as feedback from motor controls, or it has the direction “input” — such as data coming from sensors). The same thing is not true for ‘control’ data, which is deleted after being passed to the resource.
But is robot sensor data (e.g. distance reading from a sensor) handled differently than the control data sent by the arduino (e.g. when it sends joystick commands)? Because it seems that the arduino can both receive data as a resource (since it received commands that could drive the robot), yet the arduino can also send sensor data (in the case where I used the analog pins to send joystick control signals). So on the arduino, it seems that both are possible. Or am I mistaken that it is possible to do both simultaneously. E.g. that the same arduino could not both send out commands based on analog readings yet also be a “resource” that receives data to act upon?
The above conclusions are correct. We did not attempt to do both simultaneously. It seems that the architecture does not support a hardware device to act as both control as well as resource at the same time. However, we can overcome that by make it pose as “control” or “resource” component – by appropriately placing the component name in the PUT request (along with passing the correct secret key as well). So an arduino can send its robot motors data tags as being sent from ‘resource’ component and send its joystick data as being sent from ‘control2′ component. And whoever needs to pick up its data needs to specify their component names as “control” and “resource2″ respectively (either a single hardware device or two different hardware devices). Notice, if you pose yourself as “resource” and as well as “control” component names, you would simply get all the data back (works as a loopback!) – which we should avoid).
I see, this is very interesting. I like it because one of the things it would allow us to do is to have a computer attached to the internet which could control a robot entirely (instead of a human), but is not on the robot itself. So for example, ff my robot has an arduino (call it RobotArduino) can “poses” as both control and resource it could send certain data (like compass information or distance measures) to a computer that is the artificially intelligent AI controller (call it ComputerAI), that is a resource, but also able to pose as a control too. This ComputerAI receive the data readings sent out as control data from the RobotArduino and then make decisions about what actions to take and then the ComputerAI could also send a control signal back to the RobotArduino to tell it what to do. This way, the “brains” of a robot could be located anywhere in the world.
Ok, for the reason above, it might be nice to eventually have a robot capable of acting as both “control” and “resource”, so that an intelligent control loop (or brain) for the robot could be located elsewhere. Today, the only option is to have the “brain” and decisions be located in the robot. Eventually, it would be very nice if we might be able to develop smart control algorithms ourselves that operate over a network and could give remote robots various behaviours (e.g. “explore”, “sentry/guard”, “play” etc). This has been in the back of my mind for awhile as something for future phases. But I guess allowing a robot to pose as a control and resource at the same time (even if it is just adjusting the PUT and secret key lines in the code) would be a first step toward that. Maybe that could be a priority to make control/resource in one machine for the next phase of work.
Let us extend this further. Some possible scenarios are given and notes on how to implement.
- One-to-One: (One ‘control’ device to one ‘resource’ device). Such as web-to-arduino. There are only two devices and and data will simply be exchanged with each other. So it does not matter, even if you send joystick data (which we take it to mean as “control” data) as part of the resources data from arduino. The server will simply pass the data to the web, with the corresponding mapping. (We just need to make sure the Feature which defines the joystick control does not enable ‘data storage’ for historic storage purposes, unless we want it so).
- Multi-to-One: Multiple ‘control’ devices to one ‘resource’ device. Such as web, twitter to arduino. In both cases, web as well as twitter pose itself as component name “control”. And arduino will pose itself as component name ‘resource’. Both web and twitter can control the arduino resource – but if it is done at the same time, resource locking ability will take care to allow only one at the same time. In addition, the web or twitter (or pachube etc) can send the same data (like speed/direction) or web can send one set of data and twitter can send another set of data (which resource accepts) and it should work. But again not at the same time.
- One-to-Multi: One control device to multiple ‘resource’ devices (all posing as ‘control’ or ‘resource’). This will NOT work as expected, as the server would be sending some ‘control’ commands to one resource and some other to another resource, depending on which resource connects to the server and gets the data at that moment.
- Multi-to-Multi: Multiple control devices to multiple resource devices. This will only work to expected results, if each devices poses itself correctly as ‘control’, ‘control2′, ‘resource’, ‘resource2′ as its component name. They will be routed appropriately. They will follow the rules of One-to-One and Multi-to-One.
- As an example, take the case of web, arduino (driving a motor as well as joystick) and phidgets to robotic arms (controlled by arduino joystick). It will all work as expected, if web poses as ‘control’, arduino poses as ‘resource’ (for motors) and ‘control2′ (for joystick), while the phidgets will say itself as ‘resource2′. There are only three devices, but posing themselves as four endpoints. And they will all be routed appropriately.
So, I need to make changes to arduino, RobotClient and as well web to ensure that all of these can act as both control and resource. In the case of web, I can accordingly pose as “control” and “control2″ — so that the data from web can be sent to multiple resources (specifically multiple resource devices).
Update: All the above todo changes are implemented as of now.