master
parent
35d1f2adb8
commit
6ebd010edc
@ -0,0 +1,32 @@
|
||||
package com.github.rosjava.android_remocons.rocon_remocon.stranger_detect;
|
||||
|
||||
/**
|
||||
* Created by lcp on 2021/4/2.
|
||||
*/
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.rosjava.android_remocons.rocon_remocon.R;
|
||||
import com.github.rosjava.android_remocons.rocon_remocon.Remocon;
|
||||
import com.github.rosjava.android_remocons.rocon_remocon.WelcomActivity;
|
||||
|
||||
public class StrangerDialog extends AppCompatActivity {
|
||||
/*本类实现检测到陌生人后弹出提示对话框的功能*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//生成一个对话框
|
||||
AlertDialog.Builder alertdialogbuilder = new AlertDialog.Builder(this);
|
||||
alertdialogbuilder.setMessage("有陌生人进入");
|
||||
//alertdialogbuilder.setPositiveButton("我知道了", click1);
|
||||
//alertdialogbuilder.setNegativeButton("继续监视", click2);
|
||||
AlertDialog alertdialog1 = alertdialogbuilder.create();
|
||||
alertdialog1.show();
|
||||
//setContentView(R.layout.fall_alert);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.github.rosjava.android_remocons.rocon_remocon.stranger_detect;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.ros.concurrent.CancellableLoop;
|
||||
import org.ros.message.MessageListener;
|
||||
import org.ros.namespace.GraphName;
|
||||
import org.ros.node.AbstractNodeMain;
|
||||
import org.ros.node.ConnectedNode;
|
||||
import org.ros.node.topic.Subscriber;
|
||||
|
||||
public class subscriber extends AbstractNodeMain {
|
||||
/*本类实现了订阅陌生人检测信息的功能*/
|
||||
private static String TAG = "subscriber";
|
||||
|
||||
public String text = null;
|
||||
|
||||
public subscriber() {
|
||||
//判断该类是否执行
|
||||
Log.i(TAG, " is running!");
|
||||
|
||||
}
|
||||
//将提示的文本调出
|
||||
public String getAlertText(){
|
||||
return this.text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphName getDefaultNodeName() {
|
||||
return GraphName.of("rosjava_tutorial_pubsub/listener");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(final ConnectedNode connectedNode) {
|
||||
//create subscriber
|
||||
final Subscriber<std_msgs.String> subscriber =
|
||||
connectedNode.newSubscriber("chatter", std_msgs.String._TYPE);
|
||||
subscriber.addMessageListener(new MessageListener<std_msgs.String>() {
|
||||
@Override
|
||||
public void onNewMessage(std_msgs.String message) {
|
||||
text = message.getData();
|
||||
Log.i(TAG, "I heard : \"" + text + "\"");
|
||||
}
|
||||
});
|
||||
|
||||
//循环监听节点的信息
|
||||
connectedNode.executeCancellableLoop(new CancellableLoop() {
|
||||
@Override
|
||||
protected void setup() {
|
||||
/*Looper.prepare();
|
||||
Looper.loop();*/
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void loop() throws InterruptedException {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time % 1000 == 0) {
|
||||
//用于测试该节点运行了多长时间
|
||||
Log.i(TAG, "ros_node run again after 1s");
|
||||
}
|
||||
Log.i(TAG, "I heard msg from ubuntu : \"" + text+ "\"");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue