Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
fd9066fa83 | |||
cd8def574c | |||
7160cd325e | |||
fe1710b43e | |||
16ef871911 | |||
cc25e8484c |
@@ -17,8 +17,8 @@
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="ve.ucv.ciens.ccg.nxtcam"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
android:versionCode="140404"
|
||||
android:versionName="14.04.04" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="11"
|
||||
|
@@ -1,4 +1,4 @@
|
||||
NxtCAM
|
||||
======
|
||||
NxtAR-cam
|
||||
=========
|
||||
|
||||
Modulo 1 de mi trabajo especial de grado.
|
||||
|
@@ -5,7 +5,7 @@ import java.io.Serializable;
|
||||
public class MotorEvent implements Serializable{
|
||||
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 byte power;
|
||||
|
@@ -16,7 +16,8 @@
|
||||
package ve.ucv.ciens.ccg.nxtcam;
|
||||
|
||||
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.utils.Logger;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.ProjectConstants;
|
||||
@@ -40,7 +41,8 @@ public class CamActivity extends Activity{
|
||||
private CameraPreview cPreview;
|
||||
private CameraSetupTask camSetupTask;
|
||||
private VideoStreamingThread imThread;
|
||||
private LCPThread botThread;
|
||||
private NxtBTCommThread botThread;
|
||||
private SensorReportThread sensorThread;
|
||||
private String serverIp;
|
||||
|
||||
/*******************
|
||||
@@ -57,8 +59,11 @@ public class CamActivity extends Activity{
|
||||
imThread = new VideoStreamingThread(serverIp);
|
||||
imThread.start();
|
||||
|
||||
botThread = new LCPThread(serverIp);
|
||||
botThread = new NxtBTCommThread(serverIp);
|
||||
botThread.start();
|
||||
|
||||
sensorThread = new SensorReportThread(serverIp);
|
||||
sensorThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,14 +97,14 @@ public class CamActivity extends Activity{
|
||||
camSetupTask = new CameraSetupTask();
|
||||
camSetupTask.execute();
|
||||
|
||||
// imThread.start();
|
||||
// TODO: resumethe imThread, botThread and sensorThread objects.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(){
|
||||
super.onPause();
|
||||
|
||||
// TODO: pause the imThread and botThread objects.
|
||||
// TODO: pause the imThread, botThread and sensorThread objects.
|
||||
|
||||
if(cPreview != null){
|
||||
cPreview.removePreviewCallback();
|
||||
@@ -113,9 +118,12 @@ public class CamActivity extends Activity{
|
||||
super.onDestroy();
|
||||
imThread.finish();
|
||||
imThread = null;
|
||||
|
||||
|
||||
botThread.finish();
|
||||
botThread = null;
|
||||
|
||||
sensorThread.finish();
|
||||
sensorThread = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,7 +21,6 @@ import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
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.nxtcam.robotcontrol.MotorEventQueue;
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||
@@ -64,7 +63,7 @@ public class MotorControlThread extends Thread {
|
||||
if(event != null){
|
||||
queue.addEvent(event);
|
||||
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()));
|
||||
}else{
|
||||
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.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.utils.Logger;
|
||||
|
||||
public class LCPThread extends Thread{
|
||||
public class NxtBTCommThread extends 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 reportSensors;
|
||||
private BTCommunicator btComm;
|
||||
private MotorControlThread motorControl;
|
||||
private SensorReportThread sensorReport;
|
||||
|
||||
private MotorEventQueue queue;
|
||||
|
||||
public LCPThread(String serverIp){
|
||||
public NxtBTCommThread(String serverIp){
|
||||
super("Robot Control Main Thread");
|
||||
btComm = BTCommunicator.getInstance();
|
||||
done = false;
|
||||
motorControl = new MotorControlThread(serverIp);
|
||||
sensorReport = new SensorReportThread(serverIp);
|
||||
queue = MotorEventQueue.getInstance();
|
||||
}
|
||||
|
||||
public void run(){
|
||||
long then, now, delta;
|
||||
MotorEvent event;
|
||||
byte[] msg = new byte[2];
|
||||
|
||||
sensorReport.start();
|
||||
motorControl.start();
|
||||
|
||||
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){
|
||||
if(btComm.isBTEnabled() && btComm.isConnected()){
|
||||
msg[0] = 0x00;
|
||||
msg[1] = 0x00;
|
||||
|
||||
event = queue.getNextEvent();
|
||||
|
||||
try{
|
||||
btComm.writeMessage(
|
||||
LegoCommunicationProtocol.setOutputState(
|
||||
event.getMotor() == motor_t.MOTOR_A ? LegoCommunicationProtocol.PORT_0 : (event.getMotor() == motor_t.MOTOR_B ? LegoCommunicationProtocol.PORT_1 : LegoCommunicationProtocol.PORT_2),
|
||||
event.getPower())
|
||||
);
|
||||
// Set the motor bit.
|
||||
msg[0] |= (event.getMotor() == motor_t.MOTOR_A) ? MotorMasks.MOTOR_A : 0;
|
||||
msg[0] |= (event.getMotor() == motor_t.MOTOR_B) ? MotorMasks.MOTOR_B : 0;
|
||||
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.");
|
||||
|
||||
try{ sleep(40); }catch(InterruptedException ie){ }
|
||||
@@ -87,10 +90,6 @@ public class LCPThread extends Thread{
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: IOException sending message to the robot: " + io.getMessage());
|
||||
}
|
||||
|
||||
if(reportSensors){
|
||||
|
||||
}
|
||||
}else{
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: The robot disconnected or was never available.");
|
||||
break;
|
@@ -1,7 +1,7 @@
|
||||
package ve.ucv.ciens.ccg.nxtcam.network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
||||
@@ -14,21 +14,36 @@ public class SensorReportThread extends Thread{
|
||||
private Socket socket;
|
||||
private String serverIp;
|
||||
private boolean done;
|
||||
private ObjectOutputStream writer;
|
||||
private OutputStream writer;
|
||||
private boolean connected;
|
||||
private BTCommunicator btComm;
|
||||
|
||||
public SensorReportThread(String serverIp){
|
||||
super("Sensor Report Thread");
|
||||
this.serverIp = serverIp;
|
||||
done = false;
|
||||
connected = false;
|
||||
btComm = BTCommunicator.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
byte[] lightReading;
|
||||
|
||||
if(connectToServer()){
|
||||
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{
|
||||
Logger.log_e(TAG, CLASS_NAME + ".run() :: Could not connect to the server.");
|
||||
@@ -43,7 +58,7 @@ public class SensorReportThread extends Thread{
|
||||
boolean connected;
|
||||
try{
|
||||
socket = new Socket(serverIp, ProjectConstants.SENSOR_REPORT_PORT);
|
||||
writer = new ObjectOutputStream(socket.getOutputStream());
|
||||
writer = socket.getOutputStream();
|
||||
connected = true;
|
||||
}catch(IOException io){
|
||||
Logger.log_e(TAG, CLASS_NAME + ".connectToServer() :: IOException caught: " + io.getMessage());
|
||||
|
@@ -107,7 +107,7 @@ public class VideoStreamingThread extends Thread{
|
||||
imageSize = camMonitor.getImageParameters();
|
||||
|
||||
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.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