Skip to content

Daisy chaining two EV3s? #92

Closed
Closed

Description

@WasabiFan

I'm currently working on a project where I have two EV3s working in tandem. One is the host with some control logic on it, while the other controls some extra motors (just a slave). I'm trying to find the best way to control the second one with the main one over the USB connection (the host port on 1 to the client on 2). What's the best way to do this?

My preferred method would be to use a built-in protocol to control the second one, but I haven't seen any mention of a built-in USB protocol for direct control.

Activity

  1. G33kDude commented on Jul 10, 2014

    @G33kDude

    Remote execution of bash through ssh? Would probably be a bit slow, but it's the most flexible solution with the least amount of work I can think of

  2. WasabiFan commented on Jul 10, 2014

    @WasabiFan
    MemberAuthor

    I was thinking of using networking (either SSH or a client app listening on a port), but I'd rather not, simply because it's slow. I would much rather switch the second one in to a mode where it would accept direct commands; there must be preexisting drivers/USB protocols that do that, right? I just don't know how to do it... :(

  3. WasabiFan commented on Jul 10, 2014

    @WasabiFan
    MemberAuthor

    I found this header file that seems to define the protocols that the stock kernel uses to control connected EV3s. But I don't know enough C or Linux to get very far on either end (figuring out the protocols or connecting and issuing commands).

  4. G33kDude commented on Jul 10, 2014

    @G33kDude

    I'd imagine that writing your own socket listener should be sufficiently fast, as there wouldn't be any overhead with handshakes and such. Something simple and text based, like MotorLetter|speed|time or something shouldn't be too hard to implement and test if it works out okay in terms of speed

  5. dlech commented on Jul 10, 2014

    @dlech
    Member

    My personal preference would be to do as @G33kDude suggests and create your own protocol and run it over a TCP socket. You should be able to do this quite easily in any language that you like.

    A second option would be to run the official LEGO firmware. You should be able to find existing software to do this, although I haven't seen anything very complete in this regard (except the C# API from Microsoft). There are a couple of python Python projects like this floating around as well. The only one of these projects that I know of that works over USB on Linux (that I know of) is monobrick (also C#). I have played around with the USB-to-official-LEGO-firmware connection on Mac back in September, so I am somewhat familiar with what it would take to make it work.

  6. rhempel commented on Jul 10, 2014

    @rhempel
    Member

    Second the suggestion for a socket interface. Some of the official scripting languages support sending and listening on a socket - the nice thing about sockets is that the data you send out one port is reassembled and gobbled up on the other end of the socket. It just works.

  7. WasabiFan commented on Jul 10, 2014

    @WasabiFan
    MemberAuthor

    The problem is that networking slow; I might have to use it in the end, but I'm hoping for another option.

  8. WasabiFan commented on Jul 22, 2014

    @WasabiFan
    MemberAuthor

    In the end, I found that the mono library "monobrick" worked, so I decompiled it and dissected its protocols. Using that as well as the source for the official kernel, I pieced together some of my own code to do it, and was able to successfully control one stock EV3 from one running ev3dev.

  9. WasabiFan commented on Nov 29, 2014

    @WasabiFan
    MemberAuthor

    I would like to reopen this issue to discuss native daisy-chaining support.

    In the LEGO kernel, one can plug another EV3 in to the USB host port and control all of it's motors and sensors as if they were connected to the host directly. I think that having functionality like this built in to ev3dev would be a great help for building large robots without any special hardware.

    I'm imagining a scenario like this: you plug a child EV3 in to a parent EV3 and set the child in to some sort of a "slave mode". The child opens a connection with the parent and performs a handshake. At that point, the parent creates new device directories in all the normal places (tacho-motor, msensor, etc) and forwards the commands issued to those devices on to the child.

    A discussion on this topic was started over on the ev3dev-lang repo, but that wasn't very formal and didn't get past the basics. One of the topics discussed was native LEGO protocol vs. custom IP-based protocol. After some more thought, I think an IP-based solution would be better than using LEGO's protocol. Here are the points discussed:

    • Works over USB, Wi-Fi, Bluetooth, etc
    • Not proprietary, so it can be used from a host PC just as easily as from another brick
    • Pre-defined device identifiers (IP addresses)

    Anyway, what are your thoughts on this?

  10. G33kDude commented on Nov 30, 2014

    @G33kDude

    How effective do you think existing technologies such as SCP (going with speed, not security) be for this?

  11. WasabiFan commented on Nov 30, 2014

    @WasabiFan
    MemberAuthor

    That's actually an interesting idea... It's probably overkill for writing single bytes to files like we will be doing most of the time, but it's pre-made. We could probably write a script to test the speed.

  12. G33kDude commented on Nov 30, 2014

    @G33kDude

    I'm wondering if a non-encrypted protocol like ftp might be significantly faster

  13. MetallianFR68 commented on Nov 30, 2014

    @MetallianFR68

    I can easily get my EV3 bricks to "talk" together
    You can just use python or php to program a protocol using web sockets
    I'm using UDP protocol through WIFI which is really fast
    I also think that php is much faster than python

  14. dlech commented on Nov 30, 2014

    @dlech
    Member

    The goal here is clear: to be able to remotely control an EV3 running ev3dev. However, there seems to be a need to clear up some things about the possible implementation.

    For those of you not familiar with the 7 layers of the OSI model of networking, I suggest you have a look at that link. You cannot always neatly divide the parts of network communications into these layers, but I will attempt to do so anyway to help facilitate the discussion.

    To further clarify, the goal, we want to be able to remote control using any of the physical connections (layer 1) built into the EV3, namely USB and Bluetooth and also other common connections like WiFi.

    As has been mentioned several times, we want to use "sockets". To be more specific, we want to use IP (layer 3). Why? Because IP has been implemented on many different physical connections (layers 1 and 2) including all of the ones built into the EV3.

    Now, lets move up to the transport layer (layer 4). If we are using IP, we have 2 options, TCP and UDP. TCP has more overhead because there is handshaking to verify that the data packets sent did in fact arrive in-tact. UDP packets lack this verification, so they can be faster, but there is the potential of data loss.

    Next up is the session layer (layer 5). This is one thing we haven't discussed yet. When connecting via USB or Bluetooth, this does not matter so much, but consider the case that you are in a computer lab with 10 EV3s all on the same WiFi network. What is preventing you from taking control of someone else's EV3 or vice versa? I think our implementation should include some kind of session authentication. Although, we could make it optional for the connection types that don't need it.

    The presentation layer (layer 6) is the core of the discussion here. What does the data look like that we are sending? One option is to use and extend the protocol used by lms2012. The advantage is that any remote control software that is compatible with the official LEGO firmware would also be usable with ev3dev with only minor modifications. The disadvantage is that it is not user-friendly at all. Another option would be to develop our own protocol that better fits the drivers we have made for ev3dev. One thing we have to consider here is do we trade performance for readability. For example, we could make a binary protocol like lms2012 that is efficient, but not very user friendly, or do we use something like JSON to make it easier to use but sacrifice some speed.

    The final layer is the application (layer 7). This of course is the programs that will be consuming the implementation of the lower layer. Considering the fact that applications for ev3dev can be written in just about any programming language, we need to make sure our protocol is easily implemented across programming languages. We could also leverage existing application services here, such as HTTP, but again we would be sacrificing some performance (speed) due to the additional overhead.


    So, just to clear some things up:

    LEGO protocol vs. custom IP-based protocol

    As already mentioned, the official LEGO protocol is at layer 6 and IP is at layer 4, so these things are not mutually exclusive. Interesting fact: With the official LEGO firmware, the lms2012 protocol is used over 3 different types of transport. When connecting via USB, it uses HID. When using bluetooth, it uses SPP and when using WiFi, it uses UDP/IP.

    How effective do you think existing technologies such as SCP (going with speed, not security) be for this?
    I'm wondering if a non-encrypted protocol like ftp might be significantly faster

    I was going to say "SCP/FTP is for transferring files (application layer), so it is irrelevant." But, it occurred to me that it may actually be possible to mount /sys of your EV3 remotely and poke the drivers directly. However, it would not surprise me if this did not work since /sys is not a "real" file system.

    Furthermore, if you are talking about tunneling our hypothetical IP transported protocol over ssh, then it will defiantly be slower. All of the data has to be encrypted on one end and decrypted on the other which take a significant amount of time.

  15. GerardWassink commented on Jan 28, 2017

    @GerardWassink

    Curious as to how things developed since this last post...
    I like the exposé about the OSI layers, it makes things clear and gives the opportunity ti use standard protocols that are already in place.
    Furthermore, why limit it to only two EV3's? When we use WiFi, apart from computing power in a brick, there's no reason why we couldn't make it limitless right?
    .

  16. dlech commented on Jan 28, 2017

    @dlech
    Member

    I've seen some people using MQTT lately for brick-to-brick communications, but there is still no "official" built-in daisy chaining mechanism.

  17. dwalton76 commented on Jan 31, 2017

    @dwalton76

    Furthermore, why limit it to only two EV3's? When we use WiFi, apart from computing power in a brick, there's no reason why we couldn't make it limitless right?

    Agreed, I can't think of a good reason to limit it to two. SSDP could be used to find the other EV3s on the LAN. I haven't tried it yet but here is a SSDP implementation (client and server) written in python:
    https://gist.github.com/schlamar/2428250

    The next step though, the actual controlling of another ev3, I think that would need to be done via ev3dev-lang-python, ev3dev-lang-cpp, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions