From 7430eefa6fbdeda177d821b31940e315cb015bd3 Mon Sep 17 00:00:00 2001 From: Martin Vajnar Date: Mon, 5 Aug 2013 23:37:29 +0200 Subject: [PATCH] ROBOT_DEMO: fix sync. problems in publisher for "motion_speed" Don't use synchronized(), because it may block the setSpeed() and prevent receiving new data from accelerometer. The isSent variable is now used to determine whether we need new data. Add robot's IP address to the list of fellow managers. --- .../ocera/orte/demo/HokuyoScanSubscribe.java | 2 +- .../src/org/ocera/orte/demo/MainActivity.java | 5 +++-- .../ocera/orte/demo/MotionSpeedPublish.java | 18 ++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java b/orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java index 22a47e8..97b5cd5 100644 --- a/orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java +++ b/orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java @@ -25,7 +25,7 @@ public class HokuyoScanSubscribe extends SubscriptionCallback{ this.domainApp = domainApp; NtpTime deadline = new NtpTime(10); - NtpTime minSeparation = new NtpTime(0,773094113); + NtpTime minSeparation = new NtpTime(0); hokuyomsg = new HokuyoScanType(domainApp, "hokuyo_scan"); diff --git a/orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java b/orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java index d2b61d1..249e508 100644 --- a/orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java +++ b/orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java @@ -18,7 +18,7 @@ import android.view.MenuItem; public class MainActivity extends Activity { private Manager manager = null; - private String[] mgrs = {"192.168.1.5","192.168.1.8"}; + private String[] mgrs = {"192.168.1.5","192.168.1.8","10.1.1.1"}; private MotionSpeedPublish motion_speed = null; private HokuyoScanSubscribe hokuyo_scan = null; private SensorManager mSensorManager = null; @@ -55,6 +55,7 @@ public class MainActivity extends Activity { if (hokuyo_scan != null && !hokuyo_scan.isCancelled()) { hokuyo_view.run(false); hokuyo_scan.cancel(); + hokuyo_view.invalidate(); hokuyo_item.setTitle("Start hokuyo"); } @@ -165,4 +166,4 @@ public class MainActivity extends Activity { } } } -} \ No newline at end of file +} diff --git a/orte/Robot_Demo/src/org/ocera/orte/demo/MotionSpeedPublish.java b/orte/Robot_Demo/src/org/ocera/orte/demo/MotionSpeedPublish.java index d9a9850..af04f65 100644 --- a/orte/Robot_Demo/src/org/ocera/orte/demo/MotionSpeedPublish.java +++ b/orte/Robot_Demo/src/org/ocera/orte/demo/MotionSpeedPublish.java @@ -13,11 +13,11 @@ public class MotionSpeedPublish implements Runnable { private short[] speed = new short[2]; private boolean isCancelled = false; + private boolean isSent = true; private float maxRange; private float[] accelData = new float[2]; private SpeedMotionType speedmsg; private Publication pub; - private Object lock = new Object(); private Thread thread = null; private PublProp publProp; private DomainApp appDomain; @@ -81,22 +81,20 @@ public class MotionSpeedPublish implements Runnable { @Override public void run() { while(!isCancelled) { - synchronized(lock) { - calculateSpeed(accelData); - speedmsg.speed = this.speed; - - pub.send(speedmsg); - } - + calculateSpeed(accelData.clone()); + speedmsg.speed = this.speed.clone(); + pub.send(speedmsg); + isSent = true; JOrte.sleepMs(100); } } public void setSpeed(float accelX, float accelY) { - synchronized(lock) { + if(isSent) { + isSent = false; this.accelData[0] = accelX; this.accelData[1] = accelY; } } -} \ No newline at end of file +} -- 2.39.2