diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..09e0376 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,6 +4,14 @@ diff --git a/app/build.gradle b/app/build.gradle index 80b633f..ced3518 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,11 +3,11 @@ plugins { } android { - namespace 'com.example.fivewheel' + namespace 'com.example.removemarineanimals' compileSdk 34 defaultConfig { - applicationId "com.example.fivewheel" + applicationId "com.example.removemarineanimals" minSdk 24 targetSdk 34 versionCode 1 @@ -41,6 +41,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + //implementation project(':app') // 测试 testImplementation 'junit:junit:4.13.2' @@ -59,7 +60,6 @@ dependencies { def room_version = "2.6.1" implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" - // 如果以后用 Kotlin + kapt, 改成 kapt - // kapt "androidx.room:room-compiler:$room_version" + implementation "androidx.room:room-ktx:$room_version" // 可选,支持协程/LiveData } diff --git a/app/src/main/java/bsp_Error.proto b/app/src/main/java/bsp_Error.proto index a29967a..9bad973 100644 --- a/app/src/main/java/bsp_Error.proto +++ b/app/src/main/java/bsp_Error.proto @@ -1,7 +1,7 @@ syntax = "proto3"; option java_multiple_files = false; -option java_package = "com.example.fivewheel.models"; +option java_package = "com.example.removemarineanimals.models"; message ErrorData { diff --git a/app/src/main/java/bsp_IV.proto b/app/src/main/java/bsp_IV.proto index de9981e..9c67a9a 100644 --- a/app/src/main/java/bsp_IV.proto +++ b/app/src/main/java/bsp_IV.proto @@ -1,6 +1,6 @@ syntax = "proto3"; option java_multiple_files = false; -option java_package = "com.example.fivewheel.models"; +option java_package = "com.example.removemarineanimals.models"; message IV_struct_define{ @@ -17,8 +17,7 @@ message IV_struct_define{ int32 Robot_Current_Right= 10; int32 Robot_Error_Left = 11; int32 Robot_Error_Right = 12; - - int32 Robot_Compensation_Left = 13; - int32 Robot_Compensation_Right = 14; - + int32 Robot_Compensation_Left = 13; + int32 Robot_Compensation_Right = 14; + int32 Robot_RESET = 15; }; diff --git a/app/src/main/java/bsp_PV.proto b/app/src/main/java/bsp_PV.proto index fef4af0..9e58c9d 100644 --- a/app/src/main/java/bsp_PV.proto +++ b/app/src/main/java/bsp_PV.proto @@ -1,12 +1,12 @@ syntax = "proto3"; option java_multiple_files = false; -option java_package = "com.example.fivewheel.models"; +option java_package = "com.example.removemarineanimals.models"; message PV_struct_define{ int32 Robot_ChgLength= 1; - double Robot_LeftCompensation=2; - double Robot_RightCompensation=3; - double Robot_AutoSpeedBase=4; - double Robot_ManualSpeedBase=5; + double Robot_AutoSpeedBase=2; + double Robot_ManualSpeedBase=3; + int32 Robot_LaneChange_Direction = 4; + int32 Robot_Force = 5; }; diff --git a/app/src/main/java/com/example/fivewheel/MainActivity.java b/app/src/main/java/com/example/fivewheel/MainActivity.java index 895d510..96a7f7e 100644 --- a/app/src/main/java/com/example/fivewheel/MainActivity.java +++ b/app/src/main/java/com/example/fivewheel/MainActivity.java @@ -271,8 +271,6 @@ public class MainActivity extends AppCompatActivity { _toSendPV = BspPV.PV_struct_define.newBuilder() .setRobotChgLength(getSafeInt(mainBinding.tvRobotChgLength, 0)) - .setRobotLeftCompensation(0) - .setRobotRightCompensation(0) .setRobotAutoSpeedBase(getSafeDouble(mainBinding.tvRobotAutoSpeed, 0.0)) .setRobotManualSpeedBase(getSafeDouble(mainBinding.tvRobotManualSpeed, 0.0)) .build(); diff --git a/app/src/main/java/com/example/fivewheel/models/BspError.java b/app/src/main/java/com/example/fivewheel/models/BspError.java index ca7b356..1164c53 100644 --- a/app/src/main/java/com/example/fivewheel/models/BspError.java +++ b/app/src/main/java/com/example/fivewheel/models/BspError.java @@ -488,7 +488,7 @@ public final class BspError { com.example.fivewheel.models.BspError.ErrorData.class, com.example.fivewheel.models.BspError.ErrorData.Builder.class); } - // Construct using com.example.removemarineanimals.models.BspError.ErrorData.newBuilder() + // Construct using com.example.fivewheel.models.BspError.ErrorData.newBuilder() private Builder() { } @@ -795,8 +795,8 @@ public final class BspError { "\010ComError\022\r\n\tMK32_SBus\020\000\022\n\n\006TL720D\020\001\022\020\n\014" + "Force_sensor\020\002\022\020\n\014ZQ_LeftMotor\020\003\022\021\n\rZQ_R" + "ightMotor\020\004\022\013\n\007DMAKE_1\020\005\022\017\n\013MK32_Serial\020" + - "\006B*\n&com.example.removemarineanimals.mod" + - "elsP\000b\006proto3" + "\006B \n\034com.example.fivewheel.modelsP\000b\006pro" + + "to3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, diff --git a/app/src/main/java/com/example/fivewheel/models/BspPV.java b/app/src/main/java/com/example/fivewheel/models/BspPV.java index 9b4de14..d04b85e 100644 --- a/app/src/main/java/com/example/fivewheel/models/BspPV.java +++ b/app/src/main/java/com/example/fivewheel/models/BspPV.java @@ -36,25 +36,13 @@ public final class BspPV { int getRobotChgLength(); /** - * double Robot_LeftCompensation = 2; - * @return The robotLeftCompensation. - */ - double getRobotLeftCompensation(); - - /** - * double Robot_RightCompensation = 3; - * @return The robotRightCompensation. - */ - double getRobotRightCompensation(); - - /** - * double Robot_AutoSpeedBase = 4; + * double Robot_AutoSpeedBase = 2; * @return The robotAutoSpeedBase. */ double getRobotAutoSpeedBase(); /** - * double Robot_ManualSpeedBase = 5; + * double Robot_ManualSpeedBase = 3; * @return The robotManualSpeedBase. */ double getRobotManualSpeedBase(); @@ -107,32 +95,10 @@ public final class BspPV { return robotChgLength_; } - public static final int ROBOT_LEFTCOMPENSATION_FIELD_NUMBER = 2; - private double robotLeftCompensation_ = 0D; - /** - * double Robot_LeftCompensation = 2; - * @return The robotLeftCompensation. - */ - @java.lang.Override - public double getRobotLeftCompensation() { - return robotLeftCompensation_; - } - - public static final int ROBOT_RIGHTCOMPENSATION_FIELD_NUMBER = 3; - private double robotRightCompensation_ = 0D; - /** - * double Robot_RightCompensation = 3; - * @return The robotRightCompensation. - */ - @java.lang.Override - public double getRobotRightCompensation() { - return robotRightCompensation_; - } - - public static final int ROBOT_AUTOSPEEDBASE_FIELD_NUMBER = 4; + public static final int ROBOT_AUTOSPEEDBASE_FIELD_NUMBER = 2; private double robotAutoSpeedBase_ = 0D; /** - * double Robot_AutoSpeedBase = 4; + * double Robot_AutoSpeedBase = 2; * @return The robotAutoSpeedBase. */ @java.lang.Override @@ -140,10 +106,10 @@ public final class BspPV { return robotAutoSpeedBase_; } - public static final int ROBOT_MANUALSPEEDBASE_FIELD_NUMBER = 5; + public static final int ROBOT_MANUALSPEEDBASE_FIELD_NUMBER = 3; private double robotManualSpeedBase_ = 0D; /** - * double Robot_ManualSpeedBase = 5; + * double Robot_ManualSpeedBase = 3; * @return The robotManualSpeedBase. */ @java.lang.Override @@ -168,17 +134,11 @@ public final class BspPV { if (robotChgLength_ != 0) { output.writeInt32(1, robotChgLength_); } - if (java.lang.Double.doubleToRawLongBits(robotLeftCompensation_) != 0) { - output.writeDouble(2, robotLeftCompensation_); - } - if (java.lang.Double.doubleToRawLongBits(robotRightCompensation_) != 0) { - output.writeDouble(3, robotRightCompensation_); - } if (java.lang.Double.doubleToRawLongBits(robotAutoSpeedBase_) != 0) { - output.writeDouble(4, robotAutoSpeedBase_); + output.writeDouble(2, robotAutoSpeedBase_); } if (java.lang.Double.doubleToRawLongBits(robotManualSpeedBase_) != 0) { - output.writeDouble(5, robotManualSpeedBase_); + output.writeDouble(3, robotManualSpeedBase_); } getUnknownFields().writeTo(output); } @@ -193,21 +153,13 @@ public final class BspPV { size += com.google.protobuf.CodedOutputStream .computeInt32Size(1, robotChgLength_); } - if (java.lang.Double.doubleToRawLongBits(robotLeftCompensation_) != 0) { - size += com.google.protobuf.CodedOutputStream - .computeDoubleSize(2, robotLeftCompensation_); - } - if (java.lang.Double.doubleToRawLongBits(robotRightCompensation_) != 0) { - size += com.google.protobuf.CodedOutputStream - .computeDoubleSize(3, robotRightCompensation_); - } if (java.lang.Double.doubleToRawLongBits(robotAutoSpeedBase_) != 0) { size += com.google.protobuf.CodedOutputStream - .computeDoubleSize(4, robotAutoSpeedBase_); + .computeDoubleSize(2, robotAutoSpeedBase_); } if (java.lang.Double.doubleToRawLongBits(robotManualSpeedBase_) != 0) { size += com.google.protobuf.CodedOutputStream - .computeDoubleSize(5, robotManualSpeedBase_); + .computeDoubleSize(3, robotManualSpeedBase_); } size += getUnknownFields().getSerializedSize(); memoizedSize = size; @@ -226,12 +178,6 @@ public final class BspPV { if (getRobotChgLength() != other.getRobotChgLength()) return false; - if (java.lang.Double.doubleToLongBits(getRobotLeftCompensation()) - != java.lang.Double.doubleToLongBits( - other.getRobotLeftCompensation())) return false; - if (java.lang.Double.doubleToLongBits(getRobotRightCompensation()) - != java.lang.Double.doubleToLongBits( - other.getRobotRightCompensation())) return false; if (java.lang.Double.doubleToLongBits(getRobotAutoSpeedBase()) != java.lang.Double.doubleToLongBits( other.getRobotAutoSpeedBase())) return false; @@ -251,12 +197,6 @@ public final class BspPV { hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + ROBOT_CHGLENGTH_FIELD_NUMBER; hash = (53 * hash) + getRobotChgLength(); - hash = (37 * hash) + ROBOT_LEFTCOMPENSATION_FIELD_NUMBER; - hash = (53 * hash) + com.google.protobuf.Internal.hashLong( - java.lang.Double.doubleToLongBits(getRobotLeftCompensation())); - hash = (37 * hash) + ROBOT_RIGHTCOMPENSATION_FIELD_NUMBER; - hash = (53 * hash) + com.google.protobuf.Internal.hashLong( - java.lang.Double.doubleToLongBits(getRobotRightCompensation())); hash = (37 * hash) + ROBOT_AUTOSPEEDBASE_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( java.lang.Double.doubleToLongBits(getRobotAutoSpeedBase())); @@ -380,7 +320,7 @@ public final class BspPV { com.example.fivewheel.models.BspPV.PV_struct_define.class, com.example.fivewheel.models.BspPV.PV_struct_define.Builder.class); } - // Construct using com.example.removemarineanimals.models.BspPV.PV_struct_define.newBuilder() + // Construct using com.example.fivewheel.models.BspPV.PV_struct_define.newBuilder() private Builder() { } @@ -395,8 +335,6 @@ public final class BspPV { super.clear(); bitField0_ = 0; robotChgLength_ = 0; - robotLeftCompensation_ = 0D; - robotRightCompensation_ = 0D; robotAutoSpeedBase_ = 0D; robotManualSpeedBase_ = 0D; return this; @@ -436,15 +374,9 @@ public final class BspPV { result.robotChgLength_ = robotChgLength_; } if (((from_bitField0_ & 0x00000002) != 0)) { - result.robotLeftCompensation_ = robotLeftCompensation_; - } - if (((from_bitField0_ & 0x00000004) != 0)) { - result.robotRightCompensation_ = robotRightCompensation_; - } - if (((from_bitField0_ & 0x00000008) != 0)) { result.robotAutoSpeedBase_ = robotAutoSpeedBase_; } - if (((from_bitField0_ & 0x00000010) != 0)) { + if (((from_bitField0_ & 0x00000004) != 0)) { result.robotManualSpeedBase_ = robotManualSpeedBase_; } } @@ -464,12 +396,6 @@ public final class BspPV { if (other.getRobotChgLength() != 0) { setRobotChgLength(other.getRobotChgLength()); } - if (other.getRobotLeftCompensation() != 0D) { - setRobotLeftCompensation(other.getRobotLeftCompensation()); - } - if (other.getRobotRightCompensation() != 0D) { - setRobotRightCompensation(other.getRobotRightCompensation()); - } if (other.getRobotAutoSpeedBase() != 0D) { setRobotAutoSpeedBase(other.getRobotAutoSpeedBase()); } @@ -508,25 +434,15 @@ public final class BspPV { break; } // case 8 case 17: { - robotLeftCompensation_ = input.readDouble(); + robotAutoSpeedBase_ = input.readDouble(); bitField0_ |= 0x00000002; break; } // case 17 case 25: { - robotRightCompensation_ = input.readDouble(); + robotManualSpeedBase_ = input.readDouble(); bitField0_ |= 0x00000004; break; } // case 25 - case 33: { - robotAutoSpeedBase_ = input.readDouble(); - bitField0_ |= 0x00000008; - break; - } // case 33 - case 41: { - robotManualSpeedBase_ = input.readDouble(); - bitField0_ |= 0x00000010; - break; - } // case 41 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { done = true; // was an endgroup tag @@ -576,73 +492,9 @@ public final class BspPV { return this; } - private double robotLeftCompensation_ ; - /** - * double Robot_LeftCompensation = 2; - * @return The robotLeftCompensation. - */ - @java.lang.Override - public double getRobotLeftCompensation() { - return robotLeftCompensation_; - } - /** - * double Robot_LeftCompensation = 2; - * @param value The robotLeftCompensation to set. - * @return This builder for chaining. - */ - public Builder setRobotLeftCompensation(double value) { - - robotLeftCompensation_ = value; - bitField0_ |= 0x00000002; - onChanged(); - return this; - } - /** - * double Robot_LeftCompensation = 2; - * @return This builder for chaining. - */ - public Builder clearRobotLeftCompensation() { - bitField0_ = (bitField0_ & ~0x00000002); - robotLeftCompensation_ = 0D; - onChanged(); - return this; - } - - private double robotRightCompensation_ ; - /** - * double Robot_RightCompensation = 3; - * @return The robotRightCompensation. - */ - @java.lang.Override - public double getRobotRightCompensation() { - return robotRightCompensation_; - } - /** - * double Robot_RightCompensation = 3; - * @param value The robotRightCompensation to set. - * @return This builder for chaining. - */ - public Builder setRobotRightCompensation(double value) { - - robotRightCompensation_ = value; - bitField0_ |= 0x00000004; - onChanged(); - return this; - } - /** - * double Robot_RightCompensation = 3; - * @return This builder for chaining. - */ - public Builder clearRobotRightCompensation() { - bitField0_ = (bitField0_ & ~0x00000004); - robotRightCompensation_ = 0D; - onChanged(); - return this; - } - private double robotAutoSpeedBase_ ; /** - * double Robot_AutoSpeedBase = 4; + * double Robot_AutoSpeedBase = 2; * @return The robotAutoSpeedBase. */ @java.lang.Override @@ -650,23 +502,23 @@ public final class BspPV { return robotAutoSpeedBase_; } /** - * double Robot_AutoSpeedBase = 4; + * double Robot_AutoSpeedBase = 2; * @param value The robotAutoSpeedBase to set. * @return This builder for chaining. */ public Builder setRobotAutoSpeedBase(double value) { robotAutoSpeedBase_ = value; - bitField0_ |= 0x00000008; + bitField0_ |= 0x00000002; onChanged(); return this; } /** - * double Robot_AutoSpeedBase = 4; + * double Robot_AutoSpeedBase = 2; * @return This builder for chaining. */ public Builder clearRobotAutoSpeedBase() { - bitField0_ = (bitField0_ & ~0x00000008); + bitField0_ = (bitField0_ & ~0x00000002); robotAutoSpeedBase_ = 0D; onChanged(); return this; @@ -674,7 +526,7 @@ public final class BspPV { private double robotManualSpeedBase_ ; /** - * double Robot_ManualSpeedBase = 5; + * double Robot_ManualSpeedBase = 3; * @return The robotManualSpeedBase. */ @java.lang.Override @@ -682,23 +534,23 @@ public final class BspPV { return robotManualSpeedBase_; } /** - * double Robot_ManualSpeedBase = 5; + * double Robot_ManualSpeedBase = 3; * @param value The robotManualSpeedBase to set. * @return This builder for chaining. */ public Builder setRobotManualSpeedBase(double value) { robotManualSpeedBase_ = value; - bitField0_ |= 0x00000010; + bitField0_ |= 0x00000004; onChanged(); return this; } /** - * double Robot_ManualSpeedBase = 5; + * double Robot_ManualSpeedBase = 3; * @return This builder for chaining. */ public Builder clearRobotManualSpeedBase() { - bitField0_ = (bitField0_ & ~0x00000010); + bitField0_ = (bitField0_ & ~0x00000004); robotManualSpeedBase_ = 0D; onChanged(); return this; @@ -769,12 +621,11 @@ public final class BspPV { descriptor; static { java.lang.String[] descriptorData = { - "\n\014bsp_PV.proto\"\250\001\n\020PV_struct_define\022\027\n\017R" + - "obot_ChgLength\030\001 \001(\005\022\036\n\026Robot_LeftCompen" + - "sation\030\002 \001(\001\022\037\n\027Robot_RightCompensation\030" + - "\003 \001(\001\022\033\n\023Robot_AutoSpeedBase\030\004 \001(\001\022\035\n\025Ro" + - "bot_ManualSpeedBase\030\005 \001(\001B*\n&com.example" + - ".removemarineanimals.modelsP\000b\006proto3" + "\n\014bsp_PV.proto\"g\n\020PV_struct_define\022\027\n\017Ro" + + "bot_ChgLength\030\001 \001(\005\022\033\n\023Robot_AutoSpeedBa" + + "se\030\002 \001(\001\022\035\n\025Robot_ManualSpeedBase\030\003 \001(\001B" + + " \n\034com.example.fivewheel.modelsP\000b\006proto" + + "3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, @@ -785,7 +636,7 @@ public final class BspPV { internal_static_PV_struct_define_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_PV_struct_define_descriptor, - new java.lang.String[] { "RobotChgLength", "RobotLeftCompensation", "RobotRightCompensation", "RobotAutoSpeedBase", "RobotManualSpeedBase", }); + new java.lang.String[] { "RobotChgLength", "RobotAutoSpeedBase", "RobotManualSpeedBase", }); descriptor.resolveAllFeaturesImmutable(); } diff --git a/app/src/main/java/com/example/fivewheel/services/ttySerialPortHelper.java b/app/src/main/java/com/example/fivewheel/services/ttySerialPortHelper.java index 8f267a2..14b26de 100644 --- a/app/src/main/java/com/example/fivewheel/services/ttySerialPortHelper.java +++ b/app/src/main/java/com/example/fivewheel/services/ttySerialPortHelper.java @@ -86,7 +86,7 @@ public class ttySerialPortHelper { MainActivity.mainBinding.tvRobotLeftCompensation.setText(String.valueOf(_toReceiveIV.getRobotCompensationLeft()/100.0)); MainActivity.mainBinding.tvForce.setText(String.valueOf(_toReceiveIV.getRobotForceValue())); MainActivity.mainBinding.tvRobotCurrent.setText("L"+String.valueOf(_toReceiveIV.getRobotCurrentLeft()/1000) - + "R"+String.valueOf(_toReceiveIV.getRobotCurrentLeft()/1000)); + + "R"+String.valueOf(_toReceiveIV.getRobotCurrentRight()/1000)); int leftError = _toReceiveIV.getRobotErrorLeft(); int rightError = _toReceiveIV.getRobotErrorRight(); diff --git a/app/src/main/java/generate_java.bat b/app/src/main/java/generate_java.bat index 01d41da..269aa20 100644 --- a/app/src/main/java/generate_java.bat +++ b/app/src/main/java/generate_java.bat @@ -1,4 +1,6 @@ -cd /d F:\BHBF\cubeide\swj\FiveWheelAPP\app\src\main\java +cd /d D:\Android_studio_workspace\RemoveMarineAnimals\app\src\main\java protoc --proto_path=. --java_out=. bsp_IV.proto +protoc --proto_path=. --java_out=. bsp_PV.proto +protoc --proto_path=. --java_out=. bsp_Error.proto pause diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 03c9f86..7150c7a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,7 +1,5 @@ - @@ -9,561 +7,751 @@ + type="com.example.removemarineanimals.viewmodels.MainViewModel" /> + - - - - - - - - + android:orientation="horizontal" + tools:ignore="UselessParent"> - - - + - android:layout_weight="1" - android:background="@drawable/border"> - - - + android:layout_gravity="center" + android:columnCount="1" + android:orientation="vertical" + android:rowCount="9"> + + - - - - + android:orientation="horizontal"> - + + + + - + + - - - + + - - + android:layout_margin="1dp" + android:layout_weight="1" + android:gravity="right" + android:text="0" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" + tools:ignore="RtlHardcoded" /> + + + - - + - - + + + android:layout_margin="1dp" + android:layout_weight="1" + android:gravity="right" + android:text="0" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" /> + + - - - - - - - + - android:background="@drawable/border" - android:layout_weight="1"> + + + + + + - - + - - - + + + + - - + android:layout_margin="1dp" + android:layout_weight="1" + android:gravity="right" + android:text="0" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" /> + + + + + - + + + + + + - - - + + + + + + + + + + + + + + android:layout_marginHorizontal="5dp" + android:text="左电机" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" /> + android:layout_margin="1dp" + android:layout_weight="1" + android:gravity="center" + android:text="xxx" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" /> + + + + - + android:layout_marginHorizontal="5dp" + android:text="右电机" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" /> + android:layout_margin="1dp" + android:layout_weight="1" + android:gravity="center" + android:text="xxx" + android:textColor="@color/midnightblue" + android:textSize="14sp" + android:textStyle="bold" /> - - - + + + - + - - - - + + + +