Minor refactoring and more support for recording data.

This commit is contained in:
Piv
2020-04-25 15:06:40 +09:30
parent f7bb8cd774
commit 1d2253dd18
6 changed files with 72 additions and 21 deletions

View File

@@ -5,17 +5,28 @@ import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.Switch; import android.widget.Switch;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import com.google.protobuf.Empty;
import org.vato.carcontroller.LIDAR.LidarTrackingController;
import java.util.stream.Stream;
import io.grpc.stub.StreamObserver;
public class SimpleController extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener { public class SimpleController extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
private SeekBar steeringSlider; private SeekBar steeringSlider;
private SeekBar throttleSlider; private SeekBar throttleSlider;
private Switch recordSwitch; private Switch recordSwitch;
private Switch recordLidarSwitch;
private static PiLoader grpcController; private static PiLoader grpcController;
private PersonTrackingGrpc.PersonTrackingStub trackingStub;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -32,6 +43,7 @@ public class SimpleController extends AppCompatActivity implements SeekBar.OnSee
} }
recordSwitch = findViewById(R.id.recordSwitch); recordSwitch = findViewById(R.id.recordSwitch);
recordLidarSwitch = findViewById(R.id.lidarSwitch);
} }
@Override @Override
@@ -97,4 +109,24 @@ public class SimpleController extends AppCompatActivity implements SeekBar.OnSee
public void record(View view) { public void record(View view) {
grpcController.record(recordSwitch.isSelected()); grpcController.record(recordSwitch.isSelected());
} }
public void recordLidar(View view) {
StreamObserver<Empty> response = new StreamObserver<Empty>() {
@Override
public void onNext(Empty value) {
Toast.makeText(getApplicationContext(), "Started Recording Lidar", Toast.LENGTH_SHORT);
}
@Override
public void onError(Throwable t) {
Toast.makeText(getApplicationContext(), "Failed to set lidar recording", Toast.LENGTH_SHORT);
}
@Override
public void onCompleted() {
}
};
}
} }

View File

@@ -34,20 +34,10 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:text="Switch" android:onClick="record"
android:text="Record Vehicle"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Recording" />
<Button <Button
android:id="@+id/saveButton" android:id="@+id/saveButton"
@@ -55,8 +45,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:onClick="saveRecording"
android:text="Save" android:text="Save"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/lidarSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:onClick="recordLidar"
android:text="Record LiDAR"
app:layout_constraintStart_toEndOf="@+id/recordSwitch"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -5,6 +5,7 @@ import time
import car.control.motorService_pb2 as motorService_pb2 import car.control.motorService_pb2 as motorService_pb2
import car.control.motorService_pb2_grpc as motorService_pb2_grpc import car.control.motorService_pb2_grpc as motorService_pb2_grpc
from car.control.gpio.recording_vehicle_decorator import VehicleRecordingDecorator from car.control.gpio.recording_vehicle_decorator import VehicleRecordingDecorator
import google.protobuf.empty_pb2 as empty
class MotorServicer(motorService_pb2_grpc.CarControlServicer): class MotorServicer(motorService_pb2_grpc.CarControlServicer):
@@ -12,7 +13,7 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
self.vehicle = VehicleRecordingDecorator(vehicle) self.vehicle = VehicleRecordingDecorator(vehicle)
self._timer = None self._timer = None
def SetThrottle(self, request, context): def set_throttle(self, request, context):
# gRPC streams currently don't work between python and android. # gRPC streams currently don't work between python and android.
# If we don't get a response every 3 seconds, stop the car. # If we don't get a response every 3 seconds, stop the car.
print('Setting throttle to: ' + str(request.throttle)) print('Setting throttle to: ' + str(request.throttle))
@@ -20,7 +21,7 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
self.vehicle.throttle = request.throttle self.vehicle.throttle = request.throttle
return motorService_pb2.ThrottleResponse(throttleSet=True) return motorService_pb2.ThrottleResponse(throttleSet=True)
def SetSteering(self, request, context): def set_steering(self, request, context):
print('Setting steering to: ' + str(request.steering)) print('Setting steering to: ' + str(request.steering))
self.vehicle.steering = request.steering self.vehicle.steering = request.steering
return motorService_pb2.SteeringResponse(steeringSet=True) return motorService_pb2.SteeringResponse(steeringSet=True)
@@ -40,9 +41,11 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
print("Node timeout elapsed") print("Node timeout elapsed")
self.vehicle.stop() self.vehicle.stop()
def Record(self, request, context): def record(self, request, context):
"""Indicate whether the vehicle data should be recorded.""" """Indicate whether the vehicle data should be recorded."""
self.vehicle.record = request.record self.vehicle.record = request.record
return empty.Empty()
def SaveRecordedData(self, request, context): def save_recorded_data(self, request, context):
self.vehicle.save_data(request.file) self.vehicle.save_data(request.file)
return empty.Empty()

View File

@@ -9,6 +9,7 @@ from car.tracking.devices.recording_lidar import RecordingLidarDecorator
from car.messaging import messages from car.messaging import messages
import car.tracking.algorithms as alg import car.tracking.algorithms as alg
import os import os
import google.protobuf.empty_pb2 as empty
class LidarServicer(PersonTrackingServicer): class LidarServicer(PersonTrackingServicer):
@@ -28,15 +29,22 @@ class LidarServicer(PersonTrackingServicer):
def set_tracking_group(self, request, context): def set_tracking_group(self, request, context):
# Invalid groups should stop tracking # Invalid groups should stop tracking
self._tracked_group = None if request.value < 0 else request.value self._tracked_group = None if request.value < 0 else request.value
return empty.Empty()
def stop_tracking(self, request, context): def stop_tracking(self, request, context):
self._should_stream = False self._should_stream = False
self.cache.stop_scanning() self.cache.stop_scanning()
return empty.Empty()
def start_tracking(self, request, context): def start_tracking(self, request, context):
"""Starts the lidar cache, streaming on the provided port.""" """Starts the lidar cache, streaming on the provided port."""
self._should_stream = True self._should_stream = True
self.cache.start_cache() self.cache.start_cache()
return empty.Empty()
def record(self, request, context):
self._lidar.record = True
return empty.Empty()
def onGroupsChanged(self, message): def onGroupsChanged(self, message):
if self._mFactory is None: if self._mFactory is None:

View File

@@ -34,8 +34,8 @@ message SaveRequest{
} }
service CarControl{ service CarControl{
rpc SetThrottle(ThrottleRequest) returns (ThrottleResponse){} rpc set_throttle(ThrottleRequest) returns (ThrottleResponse){}
rpc SetSteering(SteeringRequest) returns (SteeringResponse){} rpc set_steering(SteeringRequest) returns (SteeringResponse){}
rpc Record(RecordingReqeust) returns (google.protobuf.Empty) {} rpc record(RecordingReqeust) returns (google.protobuf.Empty) {}
rpc SaveRecordedData(SaveRequest) returns (google.protobuf.Empty) {} rpc save_recorded_data(SaveRequest) returns (google.protobuf.Empty) {}
} }

View File

@@ -7,6 +7,7 @@ option java_package = "org.vato.carcontroller";
option java_outer_classname = "PersonTrackingProto"; option java_outer_classname = "PersonTrackingProto";
import "google/protobuf/empty.proto"; import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
message Int32Value{ message Int32Value{
int32 value = 1; int32 value = 1;
@@ -22,10 +23,15 @@ message PointScan{
repeated Point points = 1; repeated Point points = 1;
} }
service PersonTracking{ service PersonTracking{
rpc set_tracking_group(Int32Value) returns (google.protobuf.Empty) {} rpc set_tracking_group(Int32Value) returns (google.protobuf.Empty) {}
rpc stop_tracking(google.protobuf.Empty) returns (google.protobuf.Empty) {} rpc stop_tracking(google.protobuf.Empty) returns (google.protobuf.Empty) {}
rpc start_tracking(google.protobuf.Empty) returns (google.protobuf.Empty) {} rpc start_tracking(google.protobuf.Empty) returns (google.protobuf.Empty) {}
rpc record(google.protobuf.BoolValue) returns (google.protobuf.Empty) {}
} }