Merge branch 'develop'
This commit is contained in:
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="ve.ucv.ciens.ccg.nxtcam"
|
package="ve.ucv.ciens.ccg.nxtcam"
|
||||||
android:versionCode="1"
|
android:versionCode="140404"
|
||||||
android:versionName="1.0" >
|
android:versionName="14.04.04" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="11"
|
android:minSdkVersion="11"
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
NxtCAM
|
NxtAR-cam
|
||||||
======
|
=========
|
||||||
|
|
||||||
Modulo 1 de mi trabajo especial de grado.
|
Modulo 1 de mi trabajo especial de grado.
|
||||||
|
@@ -5,7 +5,7 @@ import java.io.Serializable;
|
|||||||
public class MotorEvent implements Serializable{
|
public class MotorEvent implements Serializable{
|
||||||
private static final long serialVersionUID = 9989L;
|
private static final long serialVersionUID = 9989L;
|
||||||
|
|
||||||
public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC};
|
public enum motor_t {NONE, MOTOR_A, MOTOR_B, MOTOR_C, MOTOR_AC, RECENTER};
|
||||||
|
|
||||||
private motor_t motor;
|
private motor_t motor;
|
||||||
private byte power;
|
private byte power;
|
||||||
|
@@ -16,7 +16,8 @@
|
|||||||
package ve.ucv.ciens.ccg.nxtcam;
|
package ve.ucv.ciens.ccg.nxtcam;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtcam.camera.CameraPreview;
|
import ve.ucv.ciens.ccg.nxtcam.camera.CameraPreview;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.network.LCPThread;
|
import ve.ucv.ciens.ccg.nxtcam.network.NxtBTCommThread;
|
||||||
|
import ve.ucv.ciens.ccg.nxtcam.network.SensorReportThread;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.network.VideoStreamingThread;
|
import ve.ucv.ciens.ccg.nxtcam.network.VideoStreamingThread;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
||||||
@@ -40,7 +41,8 @@ public class CamActivity extends Activity{
|
|||||||
private CameraPreview cPreview;
|
private CameraPreview cPreview;
|
||||||
private CameraSetupTask camSetupTask;
|
private CameraSetupTask camSetupTask;
|
||||||
private VideoStreamingThread imThread;
|
private VideoStreamingThread imThread;
|
||||||
private LCPThread botThread;
|
private NxtBTCommThread botThread;
|
||||||
|
private SensorReportThread sensorThread;
|
||||||
private String serverIp;
|
private String serverIp;
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
@@ -57,8 +59,11 @@ public class CamActivity extends Activity{
|
|||||||
imThread = new VideoStreamingThread(serverIp);
|
imThread = new VideoStreamingThread(serverIp);
|
||||||
imThread.start();
|
imThread.start();
|
||||||
|
|
||||||
botThread = new LCPThread(serverIp);
|
botThread = new NxtBTCommThread(serverIp);
|
||||||
botThread.start();
|
botThread.start();
|
||||||
|
|
||||||
|
sensorThread = new SensorReportThread(serverIp);
|
||||||
|
sensorThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,14 +97,14 @@ public class CamActivity extends Activity{
|
|||||||
camSetupTask = new CameraSetupTask();
|
camSetupTask = new CameraSetupTask();
|
||||||
camSetupTask.execute();
|
camSetupTask.execute();
|
||||||
|
|
||||||
// imThread.start();
|
// TODO: resumethe imThread, botThread and sensorThread objects.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause(){
|
public void onPause(){
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
// TODO: pause the imThread and botThread objects.
|
// TODO: pause the imThread, botThread and sensorThread objects.
|
||||||
|
|
||||||
if(cPreview != null){
|
if(cPreview != null){
|
||||||
cPreview.removePreviewCallback();
|
cPreview.removePreviewCallback();
|
||||||
@@ -113,9 +118,12 @@ public class CamActivity extends Activity{
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
imThread.finish();
|
imThread.finish();
|
||||||
imThread = null;
|
imThread = null;
|
||||||
|
|
||||||
botThread.finish();
|
botThread.finish();
|
||||||
botThread = null;
|
botThread = null;
|
||||||
|
|
||||||
|
sensorThread.finish();
|
||||||
|
sensorThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -21,7 +21,6 @@ import java.io.ObjectOutputStream;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
|
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEventACK;
|
import ve.ucv.ciens.ccg.networkdata.MotorEventACK;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.robotcontrol.MotorEventQueue;
|
import ve.ucv.ciens.ccg.nxtcam.robotcontrol.MotorEventQueue;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||||
@@ -64,7 +63,7 @@ public class MotorControlThread extends Thread {
|
|||||||
if(event != null){
|
if(event != null){
|
||||||
queue.addEvent(event);
|
queue.addEvent(event);
|
||||||
Logger.log_i(TAG, CLASS_NAME + ".run() :: Motor control message enqueued.");
|
Logger.log_i(TAG, CLASS_NAME + ".run() :: Motor control message enqueued.");
|
||||||
Logger.log_i(TAG, CLASS_NAME + ".run() :: Motor ID: " + (event.getMotor() == motor_t.MOTOR_A ? "MOTOR_A" : "MOTOR_C"));
|
Logger.log_i(TAG, CLASS_NAME + ".run() :: Motor ID: " + event.getMotor().toString());
|
||||||
Logger.log_i(TAG, CLASS_NAME + ".run() :: Motor power: " + Byte.toString(event.getPower()));
|
Logger.log_i(TAG, CLASS_NAME + ".run() :: Motor power: " + Byte.toString(event.getPower()));
|
||||||
}else{
|
}else{
|
||||||
Logger.log_i(TAG, CLASS_NAME + ".run() :: Message could not be verified;");
|
Logger.log_i(TAG, CLASS_NAME + ".run() :: Message could not be verified;");
|
||||||
|
@@ -19,36 +19,33 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.network.protocols.LegoCommunicationProtocol;
|
import ve.ucv.ciens.ccg.nxtcam.network.protocols.MotorMasks;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.robotcontrol.MotorEventQueue;
|
import ve.ucv.ciens.ccg.nxtcam.robotcontrol.MotorEventQueue;
|
||||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||||
|
|
||||||
public class LCPThread extends Thread{
|
public class NxtBTCommThread extends Thread{
|
||||||
private static final String TAG = "LCP_THREAD";
|
private static final String TAG = "LCP_THREAD";
|
||||||
private static final String CLASS_NAME = LCPThread.class.getSimpleName();
|
private static final String CLASS_NAME = NxtBTCommThread.class.getSimpleName();
|
||||||
|
|
||||||
private boolean done;
|
private boolean done;
|
||||||
private boolean reportSensors;
|
|
||||||
private BTCommunicator btComm;
|
private BTCommunicator btComm;
|
||||||
private MotorControlThread motorControl;
|
private MotorControlThread motorControl;
|
||||||
private SensorReportThread sensorReport;
|
|
||||||
|
|
||||||
private MotorEventQueue queue;
|
private MotorEventQueue queue;
|
||||||
|
|
||||||
public LCPThread(String serverIp){
|
public NxtBTCommThread(String serverIp){
|
||||||
super("Robot Control Main Thread");
|
super("Robot Control Main Thread");
|
||||||
btComm = BTCommunicator.getInstance();
|
btComm = BTCommunicator.getInstance();
|
||||||
done = false;
|
done = false;
|
||||||
motorControl = new MotorControlThread(serverIp);
|
motorControl = new MotorControlThread(serverIp);
|
||||||
sensorReport = new SensorReportThread(serverIp);
|
|
||||||
queue = MotorEventQueue.getInstance();
|
queue = MotorEventQueue.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
long then, now, delta;
|
long then, now, delta;
|
||||||
MotorEvent event;
|
MotorEvent event;
|
||||||
|
byte[] msg = new byte[2];
|
||||||
|
|
||||||
sensorReport.start();
|
|
||||||
motorControl.start();
|
motorControl.start();
|
||||||
|
|
||||||
then = System.currentTimeMillis();
|
then = System.currentTimeMillis();
|
||||||
@@ -62,24 +59,30 @@ public class LCPThread extends Thread{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((reportSensors = sensorReport.isConnected())){
|
|
||||||
Logger.log_d(TAG, CLASS_NAME + ".run() :: Sensor data can be reported.");
|
|
||||||
}else{
|
|
||||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Thread sensorReport could not connect to the server.");
|
|
||||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Sensor data will not be reported to server app.");
|
|
||||||
}
|
|
||||||
|
|
||||||
while(!done){
|
while(!done){
|
||||||
if(btComm.isBTEnabled() && btComm.isConnected()){
|
if(btComm.isBTEnabled() && btComm.isConnected()){
|
||||||
|
msg[0] = 0x00;
|
||||||
|
msg[1] = 0x00;
|
||||||
|
|
||||||
event = queue.getNextEvent();
|
event = queue.getNextEvent();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
btComm.writeMessage(
|
// Set the motor bit.
|
||||||
LegoCommunicationProtocol.setOutputState(
|
msg[0] |= (event.getMotor() == motor_t.MOTOR_A) ? MotorMasks.MOTOR_A : 0;
|
||||||
event.getMotor() == motor_t.MOTOR_A ? LegoCommunicationProtocol.PORT_0 : (event.getMotor() == motor_t.MOTOR_B ? LegoCommunicationProtocol.PORT_1 : LegoCommunicationProtocol.PORT_2),
|
msg[0] |= (event.getMotor() == motor_t.MOTOR_B) ? MotorMasks.MOTOR_B : 0;
|
||||||
event.getPower())
|
msg[0] |= (event.getMotor() == motor_t.MOTOR_C) ? MotorMasks.MOTOR_C : 0;
|
||||||
);
|
// Set the direction bit.
|
||||||
|
if(event.getPower() > 0) msg[0] |= MotorMasks.DIRECTION;
|
||||||
|
// Set the recenter bits.
|
||||||
|
msg[0] |= (event.getMotor() == motor_t.RECENTER) ? MotorMasks.RECENTER : 0;
|
||||||
|
if((msg[0] & MotorMasks.RECENTER) > 0)
|
||||||
|
Logger.log_i(TAG, CLASS_NAME + ".run(): Recenter received.");
|
||||||
|
|
||||||
|
// Set the power byte.
|
||||||
|
msg[1] = (byte)Math.abs(event.getPower());
|
||||||
|
|
||||||
|
// Send the message.
|
||||||
|
btComm.writeMessage(msg);
|
||||||
Logger.log_i(TAG, CLASS_NAME + ".run() :: Message sent to the robot.");
|
Logger.log_i(TAG, CLASS_NAME + ".run() :: Message sent to the robot.");
|
||||||
|
|
||||||
try{ sleep(40); }catch(InterruptedException ie){ }
|
try{ sleep(40); }catch(InterruptedException ie){ }
|
||||||
@@ -87,10 +90,6 @@ public class LCPThread extends Thread{
|
|||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: IOException sending message to the robot: " + io.getMessage());
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: IOException sending message to the robot: " + io.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reportSensors){
|
|
||||||
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: The robot disconnected or was never available.");
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: The robot disconnected or was never available.");
|
||||||
break;
|
break;
|
@@ -1,7 +1,7 @@
|
|||||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||||
@@ -14,21 +14,36 @@ public class SensorReportThread extends Thread{
|
|||||||
private Socket socket;
|
private Socket socket;
|
||||||
private String serverIp;
|
private String serverIp;
|
||||||
private boolean done;
|
private boolean done;
|
||||||
private ObjectOutputStream writer;
|
private OutputStream writer;
|
||||||
private boolean connected;
|
private boolean connected;
|
||||||
|
private BTCommunicator btComm;
|
||||||
|
|
||||||
public SensorReportThread(String serverIp){
|
public SensorReportThread(String serverIp){
|
||||||
super("Sensor Report Thread");
|
super("Sensor Report Thread");
|
||||||
this.serverIp = serverIp;
|
this.serverIp = serverIp;
|
||||||
done = false;
|
done = false;
|
||||||
connected = false;
|
connected = false;
|
||||||
|
btComm = BTCommunicator.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
|
byte[] lightReading;
|
||||||
|
|
||||||
if(connectToServer()){
|
if(connectToServer()){
|
||||||
while(!done){
|
while(!done){
|
||||||
|
if(btComm.isBTEnabled() && btComm.isConnected()){
|
||||||
|
try{
|
||||||
|
lightReading = btComm.readMessage(1);
|
||||||
|
writer.write(lightReading);
|
||||||
|
}catch(IOException io){
|
||||||
|
Logger.log_e(TAG, CLASS_NAME + "run(): IOException: " + io.getMessage());
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: The robot disconnected or was never available.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Could not connect to the server.");
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: Could not connect to the server.");
|
||||||
@@ -43,7 +58,7 @@ public class SensorReportThread extends Thread{
|
|||||||
boolean connected;
|
boolean connected;
|
||||||
try{
|
try{
|
||||||
socket = new Socket(serverIp, ProjectConstants.SENSOR_REPORT_PORT);
|
socket = new Socket(serverIp, ProjectConstants.SENSOR_REPORT_PORT);
|
||||||
writer = new ObjectOutputStream(socket.getOutputStream());
|
writer = socket.getOutputStream();
|
||||||
connected = true;
|
connected = true;
|
||||||
}catch(IOException io){
|
}catch(IOException io){
|
||||||
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: IOException caught: " + io.getMessage());
|
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: IOException caught: " + io.getMessage());
|
||||||
|
@@ -107,7 +107,7 @@ public class VideoStreamingThread extends Thread{
|
|||||||
imageSize = camMonitor.getImageParameters();
|
imageSize = camMonitor.getImageParameters();
|
||||||
|
|
||||||
yuvImage = new YuvImage(image, ImageFormat.NV21, imageSize.width(), imageSize.height(), null);
|
yuvImage = new YuvImage(image, ImageFormat.NV21, imageSize.width(), imageSize.height(), null);
|
||||||
yuvImage.compressToJpeg(imageSize, 100, outputStream);
|
yuvImage.compressToJpeg(imageSize, 90, outputStream);
|
||||||
|
|
||||||
message = new VideoFrameDataMessage();
|
message = new VideoFrameDataMessage();
|
||||||
message.data = outputStream.toByteArray();
|
message.data = outputStream.toByteArray();
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package ve.ucv.ciens.ccg.nxtcam.network.protocols;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Bit masks used to code/decode the control instructions sent by NxtAR-cam to
|
||||||
|
* NxtAR-bot.</p>
|
||||||
|
* <p>Expansions 1-3 are currently unused.</p>
|
||||||
|
*/
|
||||||
|
public abstract class MotorMasks {
|
||||||
|
public static final byte MOTOR_A = (byte)0x01;
|
||||||
|
public static final byte MOTOR_B = (byte)0x02;
|
||||||
|
public static final byte MOTOR_C = (byte)0x04;
|
||||||
|
public static final byte DIRECTION = (byte)0x08;
|
||||||
|
public static final byte RECENTER = (byte)0x10;
|
||||||
|
public static final byte EXPANSION_1 = (byte)0x20;
|
||||||
|
public static final byte EXPANSION_2 = (byte)0x20;
|
||||||
|
public static final byte EXPANSION_3 = (byte)0x20;
|
||||||
|
}
|
Reference in New Issue
Block a user