Add methods: getRemoteCommand & getRemoteCommands on EV3IRSensor #358
Comments
|
@jartu, Can you review it? |
|
Sure, I'll take a look at it. |
|
I use Intelij to compile my programs. In the ev3dev-lang-java:0.7.0.jar Thank you if you can help me. |
|
Hi @PatrickSalle, Give me few hours to review this issue, I will give you feedback today. Juan Antonio |
|
Hi @PatrickSalle, it is true but do you have one example that you need to use that commands? Cheers |
|
Hi,
I just try to interact with the robot during the execution of program, to
modify
if necesary its behaviour.
Best regards.
2018-02-06 22:47 GMT+01:00 Juan Antonio Breña Moral <
notifications@github.com>:
… Hi @PatrickSalle <https://github.com/patricksalle>, it is true but do you
have one example that you need to use that commands?
Tell me.
Cheers
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#358 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYXmUv_2grfw_S98YUhsy4q-T0_Cv7mJks5tSMhagaJpZM4OR-_v>
.
|
|
Hi @PatrickSalle, do you have some example using that methods? Juan Antonio |
|
I found this discussion: Maybe, it is a good point to begin. Juan Antonio |
|
Maybe with this example is enough to add this feature. |
|
Thank you. I if I really use this feature in a significative example I will
post
the code.
2018-02-07 17:00 GMT+01:00 Juan Antonio Breña Moral <
notifications@github.com>:
… Maybe with this example is enough to add this feature.
I will try to implement this week.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#358 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYXmUqUVJc89L-x5N3sWlH2pOxRVQAZFks5tSci2gaJpZM4OR-_v>
.
|
|
I travelled for a long time, and have not work on my project... |
|
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);
}
} |
|
Original implementation: /**
* 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);
} |
|
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 Juan Antonio |
|
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);
}
}
} |
|
Example to test the method: 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);
}
}
} |
|
Merci beaucoup. Comme je suis en voyage, je testerai à mon retour.
Cordialement, Patrick Sallé.
2018-05-04 18:54 GMT+02:00 Juan Antonio Breña Moral <
notifications@github.com>:
… 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);
}
}
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#358 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYXmUq4neXl9IFBlJhYcFjdWu3R52QK9ks5tvIe_gaJpZM4OR-_v>
.
|
|
Hello,
I have tried to create the EV3IRSensor class with the code
accessible at the address
https://github.com/ev3dev-lang-java/lejos-ev3-code-
mirror/blob/master/ev3classes/src/lejos/hardware/sensor/EV3IRSensor.java
I am not sure that it is the rigth method,
In fact I have no access to UARTPort.
import lejos.hardware.port.UARTPort;
Patrick Sallé.
2018-05-04 19:26 GMT+02:00 Juan Antonio Breña Moral <
notifications@github.com>:
… Closed #358
<#358>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#358 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYXmUgWpTCbZGAr9qLGhvgabU0H6xAHCks5tvI8ngaJpZM4OR-_v>
.
|
|
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 |
|
I am using Intellij Idea.
One of my projects is just a test of the main fonctionnalities available in
Ev3dev Lejos.
This project contains two files :
MyThirdRobot.java with the code to test getRemoteCommand as you have
suggested
EV3IRSensor.java with the code of your implementation of getRemoteCommand.
In this file the
import lejos.hardware.port.UARTPort;
fail.
I enclose a tar of the project :
2018-05-14 20:33 GMT+02:00 Juan Antonio Breña Moral <
notifications@github.com>:
… Hi @PatrickSalle <https://github.com/PatrickSalle>,
Can you paste the example that you are trying to test please?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#358 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYXmUvucLIwtBcEoptBosjR8lm1cswkUks5tyc3fgaJpZM4OR-_v>
.
|
Currently, the class EV3IRSensor has all modes implemented but in
LeJOSAPI exist 2 methods pending to implement: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:
The text was updated successfully, but these errors were encountered: