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.widget.SeekBar;
import android.widget.Switch;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
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 {
private SeekBar steeringSlider;
private SeekBar throttleSlider;
private Switch recordSwitch;
private Switch recordLidarSwitch;
private static PiLoader grpcController;
private PersonTrackingGrpc.PersonTrackingStub trackingStub;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -32,6 +43,7 @@ public class SimpleController extends AppCompatActivity implements SeekBar.OnSee
}
recordSwitch = findViewById(R.id.recordSwitch);
recordLidarSwitch = findViewById(R.id.lidarSwitch);
}
@Override
@@ -97,4 +109,24 @@ public class SimpleController extends AppCompatActivity implements SeekBar.OnSee
public void record(View view) {
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_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Switch"
android:onClick="record"
android:text="Record Vehicle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
<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" />
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/saveButton"
@@ -55,8 +45,20 @@
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginEnd="16dp"
android:onClick="saveRecording"
android:text="Save"
app:layout_constraintEnd_toEndOf="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>

View File

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

View File

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

View File

@@ -34,8 +34,8 @@ message SaveRequest{
}
service CarControl{
rpc SetThrottle(ThrottleRequest) returns (ThrottleResponse){}
rpc SetSteering(SteeringRequest) returns (SteeringResponse){}
rpc Record(RecordingReqeust) returns (google.protobuf.Empty) {}
rpc SaveRecordedData(SaveRequest) returns (google.protobuf.Empty) {}
rpc set_throttle(ThrottleRequest) returns (ThrottleResponse){}
rpc set_steering(SteeringRequest) returns (SteeringResponse){}
rpc record(RecordingReqeust) 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";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";
message Int32Value{
int32 value = 1;
@@ -22,10 +23,15 @@ message PointScan{
repeated Point points = 1;
}
service PersonTracking{
rpc set_tracking_group(Int32Value) 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 record(google.protobuf.BoolValue) returns (google.protobuf.Empty) {}
}