★ wanayoo — archive 1999 https://github.com/ev3dev-lang-java/ev3dev-lang-java/issues/358Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods: getRemoteCommand & getRemoteCommands on EV3IRSensor #358

Closed
jabrena opened this issue Jul 9, 2017 · 21 comments
Closed

Add methods: getRemoteCommand & getRemoteCommands on EV3IRSensor #358

jabrena opened this issue Jul 9, 2017 · 21 comments

Comments

@jabrena
Copy link
Member

@jabrena jabrena commented Jul 9, 2017 •

Currently, the class EV3IRSensor has all modes implemented but in LeJOS API exist 2 methods pending to implement:

int | getRemoteCommand(int chan)Return the current remote command from the specified channel.
void | getRemoteCommands(byte[] cmds, int offset, int len)Obtain the commands associated with one or more channels.

It is necessary to add methods: getRemoteCommand & getRemoteCommands in the class: EV3IRSensor.

https://ev3dev-lang-java.github.io/docs/api/latest/ev3dev-lang-java/ev3dev/sensors/ev3/EV3IRSensor.html
http://www.lejos.org/ev3/docs/lejos/hardware/sensor/EV3IRSensor.html
https://github.com/ev3dev-lang-java/lejos-ev3-code-mirror/blob/master/ev3classes/src/lejos/hardware/sensor/EV3IRSensor.java

Goals:

  • SystemTest the sensor with the implementation of getRemoteCommand
  • SystemTest the sensor with the implementation of getRemoteCommands
  • Remove getRemoteMode from the sensor
  • Added UnitTest for methods
@jabrena
Copy link
Member Author

@jabrena jabrena commented Jul 9, 2017

@jartu, Can you review it?

@jartu
Copy link
Contributor

@jartu jartu commented Jul 9, 2017

Sure, I'll take a look at it.

@jabrena jabrena modified the milestones: v0.8.0, v0.7.0 Aug 12, 2017
@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented Feb 6, 2018

I use Intelij to compile my programs. In the ev3dev-lang-java:0.7.0.jar
I have not the getRemoteCommand methods.
What I have to do to get this method?
In my external librairies I refer Gradle:com.github.ev3dev-lang-java:0.7.0

Thank you if you can help me.
Patrick Sallé

@jabrena
Copy link
Member Author

@jabrena jabrena commented Feb 6, 2018

Hi @PatrickSalle,

Give me few hours to review this issue, I will give you feedback today.

Juan Antonio

@jabrena
Copy link
Member Author

@jabrena jabrena commented Feb 6, 2018

Hi @PatrickSalle, it is true but do you have one example that you need to use that commands?
Tell me.

Cheers

@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented Feb 7, 2018

@jabrena
Copy link
Member Author

@jabrena jabrena commented Feb 7, 2018

Hi @PatrickSalle,

do you have some example using that methods?

Juan Antonio

@jabrena
Copy link
Member Author

@jabrena jabrena commented Feb 7, 2018

I found this discussion:
https://lejos.sourceforge.io/forum/viewtopic.php?t=7665

Maybe, it is a good point to begin.

Juan Antonio

@jabrena
Copy link
Member Author

@jabrena jabrena commented Feb 7, 2018

Maybe with this example is enough to add this feature.
I will try to implement this week.

@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented Feb 7, 2018

@jabrena jabrena modified the milestones: v0.8.0, v0.9.0 Mar 13, 2018
@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented Apr 9, 2018

I travelled for a long time, and have not work on my project...
Have look at the getRemoteCommand?
Best regards.
Patrick.

@jabrena
Copy link
Member Author

@jabrena jabrena commented Apr 30, 2018 •

Ideas to implement the method:

		// Get the IR commands
			byte [] cmds = new byte[4];
			ir.getRemoteCommands(cmds, 0, cmds.length);
			
			// Figure out which channel is active:
			int command = 0;
			for(int i=0;i<4;i++) {
				if(cmds[i] > 0) {
					channel = i;
					command = cmds[i];
				}
			}
public static void IRSensorTest()
    {
        RegulatedMotor m = new EV3LargeRegulatedMotor(MotorPort.A);

        Port port = LocalEV3.get().getPort("S4");
        EV3IRSensor ir = new EV3IRSensor(port);
        while(true)
        {
            System.out.println("cmd " + ir.getRemoteCommand(0)); // gets command from channel 1
            if (ir.getRemoteCommand(0) == 1) m.forward();
            else if (ir.getRemoteCommand(0) == 2) m.backward();
            Delay.msDelay(50);
        }
    }
@jabrena
Copy link
Member Author

@jabrena jabrena commented Apr 30, 2018 •

Original implementation:
https://github.com/ev3dev-lang-java/lejos-ev3-code-mirror/blob/master/ev3classes/src/lejos/hardware/sensor/EV3IRSensor.java

    /**
     * Return the current remote command from the specified channel. Remote commands
     * are a single numeric value  which represents which button on the Lego IR
     * remote is currently pressed (0 means no buttons pressed). Four channels are
     * supported (0-3) which correspond to 1-4 on the remote. The button values are:<br>
     * 1 TOP-LEFT<br>
     * 2 BOTTOM-LEFT<br>
     * 3 TOP-RIGHT<br>
     * 4 BOTTOM-RIGHT<br>
     * 5 TOP-LEFT + TOP-RIGHT<br>
     * 6 TOP-LEFT + BOTTOM-RIGHT<br>
     * 7 BOTTOM-LEFT + TOP-RIGHT<br>
     * 8 BOTTOM-LEFT + BOTTOM-RIGHT<br>
     * 9 CENTRE/BEACON<br>
     * 10 BOTTOM-LEFT + TOP-LEFT<br>
     * 11 TOP-RIGHT + BOTTOM-RIGHT<br>
     * @param chan channel to obtain the command for
     * @return the current command
     */
    public int getRemoteCommand(int chan)
    {
        switchMode(IR_REMOTE, SWITCH_DELAY);
        port.getBytes(remoteVals, 0, remoteVals.length);
        return remoteVals[chan] & 0xff;
    }

    /**
     * Obtain the commands associated with one or more channels. Each element of 
     * the array contains the command for the associated channel (0-3).
     * @param cmds the array to store the commands
     * @param offset the offset to start storing
     * @param len the number of commands to store.
     */
    public void getRemoteCommands(byte[] cmds, int offset, int len)
    {
        switchMode(IR_REMOTE, SWITCH_DELAY);
        port.getBytes(cmds, offset, len);
    }
@jabrena
Copy link
Member Author

@jabrena jabrena commented Apr 30, 2018

Hi @PatrickSalle,

I could implement the methods, the solution was not very complicated but I am not able to test in few days. If you have time, I could create a Snapshot to test in your project.

Do you use Debian Jessie or Debian Stretch?

Juan Antonio

@jabrena
Copy link
Member Author

@jabrena jabrena commented May 4, 2018 •

Example to test the feature:

package example;

import ev3dev.sensors.ev3.EV3IRSensor;
import lejos.hardware.port.SensorPort;
import lejos.utility.Delay;

public class IRTest {

    public static void main(String[] args) {

        EV3IRSensor ir = new EV3IRSensor(SensorPort.S1);
        
        for(int i=0;i<40;i++) {
            System.out.println("cmd " + ir.getRemoteCommand(0)); // gets command from channel 1
            Delay.msDelay(500);
        }

    }

}
@jabrena
Copy link
Member Author

@jabrena jabrena commented May 4, 2018

Example to test the method: getRemoteCommands

package example;

import ev3dev.sensors.ev3.EV3IRSensor;
import lejos.hardware.port.SensorPort;
import lejos.utility.Delay;

public class IRTest2 {

    public static void main(String[] args) {

        EV3IRSensor ir = new EV3IRSensor(SensorPort.S1);

        byte[] commands = new byte[EV3IRSensor.IR_CHANNELS];

        for(int i=0;i<40;i++) {
            ir.getRemoteCommands(commands, 0, commands.length);
            System.out.println("cmd1 " + commands[0]); // gets command from channel 1
            System.out.println("cmd2 " + commands[1]); // gets command from channel 2
            System.out.println("cmd3 " + commands[2]); // gets command from channel 3
            System.out.println("cmd4 " + commands[3]); // gets command from channel 4

            Delay.msDelay(500);
        }

    }

}
@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented May 4, 2018

jabrena added a commit that referenced this issue May 4, 2018
Feature/#358
@jabrena jabrena added resolved and removed testing labels May 4, 2018
@jabrena jabrena closed this May 4, 2018
@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented May 14, 2018 •

@jabrena
Copy link
Member Author

@jabrena jabrena commented May 14, 2018 •

Hi @PatrickSalle,

Can you paste the example that you are trying to test please?

I noticed that the classs has this constructor:

    public EV3IRSensor(UARTPort port)
    {
        super(port, IR_PROX);
        init();
    }

But in the port to EV3Dev, it is not necessary.

Use this way:

EV3IRSensor ir = new EV3IRSensor(SensorPort.S1);

Juan Antonio

@PatrickSalle
Copy link

@PatrickSalle PatrickSalle commented May 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.