mit-cml / appinventor-sources

MIT App Inventor Public Open Source
http://appinventor.mit.edu/appinventor-sources/
Apache License 2.0
1.48k stars 2.07k forks source link

EV3 Bluetooth Messaging support #1512

Open neilmunday opened 5 years ago

neilmunday commented 5 years ago

Could support for the Lego EV3 mindstorms Bluetooth "mailbox messaging" support to be added please?

"Jerry" has had some success by implementing the feature in the App Inventor designer (see: https://r.jander.me.uk/index.php/2016/09/04/ev3-mailbox-messaging/#comment-408) but it would be great if a App Inventor had an EV3 Messaging component that could handle sending text, logic and numeric values to an EV3 as well.

ewpatton commented 5 years ago

The core team doesn't have the bandwidth to implement this, but it sounds like it would be a good student project. I've marked it as "help wanted" if someone wants to implement this.

tasos12 commented 5 years ago

Hello guys as part of the introduction phase of GSoC 2019 i would like to help resolving this issue. I have both knowledge and access to Ev3 software and hardware. This is my first time contributing to the project so is it possible you can give me some guidelines and advices before I start researching this issue?

ewpatton commented 5 years ago

@tasos12 You should read through the contributing section in the README.md file. For this project, make sure you branch from the ucr branch rather than master. You might also want to familiarize yourself with how some of the other Ev3 components work, such as Ev3Motors, Ev3Sound, and Ev3Commands.

tasos12 commented 5 years ago

@ewpatton This is a class skeleton for a new component that supports Ev3 Bluetooth messaging `public class Ev3Mailbox{ public Ev3Mailbox(){}

//Sends a string to ev3
 public SendMailboxText(String message){
     byte[] command = Ev3BinaryParser.encodeSystemCommand(Ev3Constants.SystemCommand.WRITEMAILBOX, false, message);
     sendCommand(functionName);
 }

 //Sends an integer to Ev3
 public SendMailboxInt(int message){
     byte[] command = Ev3BinaryParser.encodeSystemCommand(Ev3Constants.SystemCommand.WRITEMAILBOX, false, message);
     sendCommand(functionName);
 }

} `

I would like to ask am I in right track? What I noticed is that in the encodeSystemCommand boolean or float is not supported as a parameter of the command. Should I fix this somehow or is there something that I missed.

ewpatton commented 5 years ago

It looks like a good start. Please read through https://docs.google.com/document/d/1xk9dMfczvjbbwD-wMsr-ffqkTlE3ga0ocCE1KOb2wvw/pub for more information about writing new components.

Also, are those the only two types of data that one can send to the mailbox?

Sent from my iPhone

On Mar 27, 2019, at 18:28, Gkagkas Anastasios notifications@github.com wrote:

@ewpatton This is a class skeleton for a new component that supports Ev3 Bluetooth messaging `public class Ev3Mailbox{ public Ev3Mailbox(){}

//Sends a string to ev3 public SendMailboxText(String message){ byte[] command = Ev3BinaryParser.encodeSystemCommand(Ev3Constants.SystemCommand.WRITEMAILBOX, false, message); sendCommand(functionName); }

//Sends an integer to Ev3 public SendMailboxInt(int message){ byte[] command = Ev3BinaryParser.encodeSystemCommand(Ev3Constants.SystemCommand.WRITEMAILBOX, false, message); sendCommand(functionName); } } `

I would like to ask am I in right track? What I noticed is that in the encodeSystemCommand boolean or float is not supported as a parameter of the command. Should I fix this somehow or is there something that I missed.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

neilmunday commented 5 years ago

You can write a string, float or Boolean to an EV3 mailbox.

tasos12 commented 5 years ago

Yes indeed but the method Ev3BinaryParser.encodeSystemCommand has no case for a boolean or a float passed as an argument. I believe two more cases should be added for each type and then build the rest of the Ev3mailbox component. I will also test if it works properly with text before going into further changes.

ewpatton commented 5 years ago

Please do add the other variants for encodeSystemCommand so that we can cover the full range of types.

On Mar 28, 2019, at 06:48, Gkagkas Anastasios notifications@github.com wrote:

Yes indeed but the method Ev3BinaryParser.encodeSystemCommand has no case for a boolean or a float passed as an argument. I believe two more cases should be added for each type and then build the rest of the Ev3mailbox component. I will also test if it works properly with text before going into further changes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

tasos12 commented 5 years ago

@ewpatton I managed to build a component that is able to send text and the tests were succesfull. Heres the code.

@DesignerComponent(version= YaVersion.EV3_MOTORS_COMPONENT_VERSION,
        description = "A component that provides high level interfaces to a LEGO MINDSTORMS EV3 " +
                "robot, with functions that can send messages to the Ev3 mailbox.",
        category = ComponentCategory.LEGOMINDSTORMS,
        nonVisible = true,
        iconName = "images/legoMindstormsEv3.png")
@SimpleObject
public class Ev3Mailbox extends LegoMindstormsEv3Base{

    public Ev3Mailbox(ComponentContainer container){
        super(container, "Ev3Mailbox");
    }

    @SimpleFunction(description = "Send a text message")
    public void SendMailboxText(String name, String message){
        String functionName = "SendMailboxText";
        //size_h = Math.floor
        byte[] command = Ev3BinaryParser.encodeSystemCommand(Ev3Constants.SystemCommand.WRITEMAILBOX,
                                                            false,
                                                            (byte) (name.length()+1),
                                                            name,
                                                            (short) (message.length()+1),
                                                            message);
        sendCommand(functionName, command, false);
    }
}

I think now it's safe to add the rest methods supporting float and boolean values Should i proceed with the changes or is anything left?

ewpatton commented 5 years ago

I would like to see the full breadth of types supported, so go ahead and implement the boolean and float operations as well. Once that's done, please submit a pull request. It would be nice if you include an example program for the Ev3 so that we can test it here.