Is gloomyandy's code on EV3 to EV3 Motor control not working anymore?

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

wrighter
New User
Posts: 2
Joined: Fri May 11, 2018 12:13 pm

Is gloomyandy's code on EV3 to EV3 Motor control not working anymore?

Postby wrighter » Fri May 11, 2018 12:40 pm

Hello,

I have a project in which I want to make EV3s control and send data one to another.
I`m currently stuck at making one EV3 control the motor of another, just like gloomyandy's blog post found at: https://lejosnews.wordpress.com/2015/02/26/ev3-to-ev3-motor-control/ , and I just pasted his code, but I get the following exception: Got exception java.lang.ArrayIndexOutOfBoundsException: 0

Keep in mind I literally pasted the code without changing anything.

I understand that the error above is when an array is empty, but I can`t figure out which one and why.
Regarding my set-up, I managed to control my two EV3s remotely from my PC using WiFi. In addition, the PAN set-up as both my EV3s have two IPs. One from my PCs DHCP server, as they are connected to my hotspot, and then one from the PAN configuration. 10.0.0.1 and 10.0.0.2.

I`ve tried to eliminate the last two elements of the "names" dictionary, so that I only have EV1 and EV2, but that doesn`t fix the issue.
I managed to remotely control each of the EV3s and make use of the motors and sensors, as well as remotely accessing the Audio interface from an EV3 to another.

The code I'm trying to use is:

Code: Select all

public static void remoteMotorTest()
{
    String[] names = {"EV1", "EV2", "EV3", "EV4"};
    RemoteRequestEV3[] bricks = new RemoteRequestEV3[names.length];
    try {
        for(int i = 1; i < names.length; i++)
            bricks[i] = new RemoteRequestEV3(BrickFinder.find(names[i])[0].getIPAddress());
        RegulatedMotor[] motors = new RegulatedMotor[bricks.length*2];
        motors[0] = new EV3LargeRegulatedMotor(BrickFinder.getLocal().getPort("A"));
        motors[1] = new EV3LargeRegulatedMotor(BrickFinder.getLocal().getPort("B"));
        for(int i = 1; i < bricks.length; i++)
        {
            motors[i*2] = bricks[i].createRegulatedMotor("A", 'L');
            motors[i*2+1] = bricks[i].createRegulatedMotor("B", 'L');
        }
 
        for(RegulatedMotor m : motors)
        {
            m.setAcceleration(900);
            m.setSpeed(600);
        }
 
        for(RegulatedMotor m : motors)
            m.rotate(720);
        for(RegulatedMotor m : motors)
            m.rotate(-720);
        for(RegulatedMotor m : motors)
            m.rotate(720, true);
        for(RegulatedMotor m : motors)
            m.waitComplete();
 
        for(RegulatedMotor m : motors)
            m.rotate(-720, true);
        for(RegulatedMotor m : motors)
            m.waitComplete();
 
        for(int i = 0; i < 4; i++)
            for(RegulatedMotor m : motors)
                m.rotate(90);
        for(RegulatedMotor m : motors)
            m.rotate(-720, true);
        for(RegulatedMotor m : motors)
            m.waitComplete();
 
        for(int i = 0; i < motors.length; i++)
        {
            motors[i].setSpeed((i+1)*100);
            motors[i].setAcceleration((i+1)*100);
        }
        for(int i = 0; i < motors.length; i++)
            motors[i].rotate((i+1)*360, true);
        for(RegulatedMotor m : motors)
            m.waitComplete();
 
        for(RegulatedMotor m : motors)
            m.close();
 
        for(int i = 1; i < bricks.length; i++)
            bricks[i].disConnect();
    }
    catch (Exception e)
    {
        System.out.println("Got exception " + e);
    }
}   


Let me know if you need additional info to help me out with the issue.
Thanks!

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Is gloomyandy's code on EV3 to EV3 Motor control not working anymore?

Postby gloomyandy » Fri May 11, 2018 6:16 pm

You need to post the details of the exception it will tell you which line the problem is occurring at.
leJOS news https://lejosnews.wordpress.com/

wrighter
New User
Posts: 2
Joined: Fri May 11, 2018 12:13 pm

Re: Is gloomyandy's code on EV3 to EV3 Motor control not working anymore?

Postby wrighter » Sat May 12, 2018 8:41 am

So I added the

Code: Select all

e.printStackTrace();
line and so the exception happens at line 19 which is

Code: Select all

bricks[i] = new RemoteRequestEV3(BrickFinder.find(names[i])[0].getIPAddress());
but I have no idea why.

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Is gloomyandy's code on EV3 to EV3 Motor control not working anymore?

Postby gloomyandy » Sat May 12, 2018 11:17 am

For some reason the brick is unable to find the other brick(s) you are trying to talk to. Are you sure that you have the correct names for the bricks you are trying to talk to? I'm a little confused as to how you have things setup in terms of networking. If all of your EV3s have a WiFi connection then you do not need to setup a PAN between them just use the WiFi. Either way your first step is to find out what is happening with the calls to BrickFinder. If all else fails you can hard code the IP address of the other brick{s) and use that.
leJOS news https://lejosnews.wordpress.com/


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest