Home » Archive by category "Java" (Page 3)

RaspInLoop

Hello all,

I just came into something that might be interesting to simulate and debug applications using PI4J.  Have a look at RaspInLoop.  I am an IntelliJ user so I can’t test it.  Hopefully there will come something similar for IntelliJ.

Jan

Continue reading »

New Car Chassis

Hello all,

first of all I want to wish you all a very happy 2016.  Hope all your dreams may come true and mine of course.

During the Winter holidays I took the opportunity to order a new chassis for the Raspberry Pi Controlled Car.  The one I got was not good.  Pieces were missing or incorrect and that made it not as expected.  The package came from China and was cheap so I won’t complain.  It’s sometimes a risk we have to take.  Anyway, I did use that chassis to do my first developments and tests so it was not a waste of money.  Once the new chassis was there, I directly started setting it up and and let it drive.  You can see some pictures here under.  I am pretty satisfied I got it working.  I made a little interface in JavaFX with a couple of buttons : Forward, Backward, Left, Right and a speed slider.  That’s all I need for the moment in the interface.  As I said.  Very simple.  The interface is running on my laptop and it communicates via RMI towards my developments installed on the Raspberry Pi.  It is working well although I notice sometimes a lack of responsiveness.  Question is if my choice for RMI is the reason for that or not.  I haven’t taken the time to investigate if I could use for example a light webservice (REST) to speed up.  Anyway, the goal was to let it move and turn …  Now I need to do the finetuning when I have time.

IMG_2220 IMG_2221 IMG_2219

Continue reading »

Need for Spring ?

I have a setupCar method which initializes the inputs (individual motors)I use on my RPD (Raspberry Pi Driven) Car.  When I look at the code I notice this is not ideal. Too much hardcoded dependencies and this is not really something I want.  Imagine I would like to swtich pins because a pin broke,  …  I would have to modify the method and do a new build.  If I was using Spring I would only have to change the bean xml file and up we go.  I prefer to have some flexibility. As mentioned, Spring might bring the solution but I need to have a look at that and try to find out if I can configure the PI4J depencies in a Spring bean xml file. The source code as it is now, smells dirty.

See source of the method setupCar as it is now here under :

     public void setupCar() {
        input1 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02,
                "INPUT1",
                PinState.LOW);
        input2 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03,
                "INPUT2",
                PinState.LOW);
        input3 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05,
                "INPUT3",
                PinState.LOW);
        input4 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06,
                "INPUT4",
                PinState.LOW);
        leftWheel = new Wheel(0, input1, input2);
        rightWheel = new Wheel(4, input3, input4);
        wheelAxle = new WheelAxle(leftWheel, rightWheel);
        car = new TwoWheelDriveRaspyCar(wheelAxle);
    }

Continue reading »

RMI finally working

My research on how to use RMI wasn’t really a piece of cake.  In a first stage I tried an sample using the rmic to generate the stub which went fairly easy.  But afterwards I found out that this was not really the way to go since this solution was oldfashioned.  I than tried the general accepted way which is described on an Oracle tutorial

Coding went well since you don’t really have to do a lot but getting it to work that was another story.  Starting the service side of the story was a real pain.  You have to use a parameter called “java.rmi.server.codebase” at startup.  The codebase identifies the location of the remote class files or jar containing the classes.  Probably this definition is not 100% correct but it works for me.  Anyway.  I first had to setup a webserver (apache2) which serves the jar file so I can access it via a simple url.  Quite simple.  But the the proof of the pudding is in the eating so I started the server side and it complained that my remote class was not found.  I must have checked tens of times for typo’s but no clue what was wrong.  After some googling I found out that as of JDK 7 update 21, a parameter called “java.rmi.server.useCodebaseOnly” is set default to true, which was not the case before.  As a result (I use JDK7 update 40) the codebase parameter was ignored at startup.  Instead this parameter had to be foreseen for the rmiregistry command and than everything worked well.

So to summarize.  To start the server part you have to do the following (this is in the context of my concrete example)

  • rmiregistry -J-Djava.rmi.server.codebase=http://192.168.1.150/Example-1.5-SNAPSHOT.jar &
  • sudo java -cp Example-1.5-SNAPSHOT.jar:.:class:/opt/pi4j/lib/’*’:log4j-1.2.17.jar -Djava.rmi.server.hostname=192.168.1.150 be.byle.raspycar.RemoteTwoWheelDriveRaspyCar

Having got RMI working, it is time now to continue with the next steps and improving my code.

 

Have a nice Sunday evening,

Jan

Continue reading »