diff --git a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_CV.pb.h b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_CV.pb.h index 4131a6c..31d874f 100644 --- a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_CV.pb.h +++ b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_CV.pb.h @@ -68,7 +68,7 @@ extern const pb_msgdesc_t CV_struct_define_msg; /* Maximum encoded size of messages (where known) */ #define BSP_CV_PB_H_MAX_SIZE CV_struct_define_size -#define CV_struct_define_size 134 +#define CV_struct_define_size 156 #ifdef __cplusplus } /* extern "C" */ diff --git a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_GV.pb.h b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_GV.pb.h index 17f78b0..786364f 100644 --- a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_GV.pb.h +++ b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_GV.pb.h @@ -112,7 +112,7 @@ extern const pb_msgdesc_t GV_struct_define_msg; /* Maximum encoded size of messages (where known) */ #define BSP_GV_PB_H_MAX_SIZE GV_struct_define_size -#define GV_struct_define_size 1680 +#define GV_struct_define_size 1702 #ifdef __cplusplus } /* extern "C" */ diff --git a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_PV.pb.h b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_PV.pb.h index 151be78..6c0f0e4 100644 --- a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_PV.pb.h +++ b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/PSource/bsp_PV.pb.h @@ -15,6 +15,8 @@ typedef struct _PV_struct_define { int32_t knife_descending_height; int32_t main_axis_speed; int32_t step_len; + int32_t scan_len; + int32_t scan_back_len; } PV_struct_define; @@ -23,21 +25,25 @@ extern "C" { #endif /* Initializer values for message structs */ -#define PV_struct_define_init_default {0, 0, 0, 0} -#define PV_struct_define_init_zero {0, 0, 0, 0} +#define PV_struct_define_init_default {0, 0, 0, 0, 0, 0} +#define PV_struct_define_init_zero {0, 0, 0, 0, 0, 0} /* Field tags (for use in manual encoding/decoding) */ #define PV_struct_define_robot_operation_mode_tag 1 #define PV_struct_define_knife_descending_height_tag 2 #define PV_struct_define_main_axis_speed_tag 3 #define PV_struct_define_step_len_tag 4 +#define PV_struct_define_scan_len_tag 5 +#define PV_struct_define_scan_back_len_tag 6 /* Struct field encoding specification for nanopb */ #define PV_struct_define_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, INT32, robot_operation_mode, 1) \ X(a, STATIC, SINGULAR, INT32, knife_descending_height, 2) \ X(a, STATIC, SINGULAR, INT32, main_axis_speed, 3) \ -X(a, STATIC, SINGULAR, INT32, step_len, 4) +X(a, STATIC, SINGULAR, INT32, step_len, 4) \ +X(a, STATIC, SINGULAR, INT32, scan_len, 5) \ +X(a, STATIC, SINGULAR, INT32, scan_back_len, 6) #define PV_struct_define_CALLBACK NULL #define PV_struct_define_DEFAULT NULL @@ -48,7 +54,7 @@ extern const pb_msgdesc_t PV_struct_define_msg; /* Maximum encoded size of messages (where known) */ #define BSP_PV_PB_H_MAX_SIZE PV_struct_define_size -#define PV_struct_define_size 44 +#define PV_struct_define_size 66 #ifdef __cplusplus } /* extern "C" */ diff --git a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/Proto/bsp_PV.proto b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/Proto/bsp_PV.proto index 1b10ebc..4431d60 100644 --- a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/Proto/bsp_PV.proto +++ b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Protobuf/Proto/bsp_PV.proto @@ -5,4 +5,6 @@ message PV_struct_define{ int32 knife_descending_height = 2; int32 main_axis_speed = 3; int32 step_len = 4; + int32 scan_len = 5; + int32 scan_back_len = 6; }; diff --git a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Src/FSM.c b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Src/FSM.c index e8a7cd6..b111f1e 100644 --- a/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Src/FSM.c +++ b/diaoerqiege/BHBF_Robot_Lifting_Lug/Core/Src/FSM.c @@ -169,23 +169,83 @@ void IO_Control() } +#define RISE_KINFE_STATE -11 +#define FORWARD_STATE 11 +#define BACKWARD_STATE 21 + int32_t MaxLaserSensor = -255; // 激光传感器最大值,初始化为非法值 int32_t knife_descent_height = -255; // "下降高度"迭代值,初始赋值为非法值 +int32_t ScanTimeCount = 0; +int32_t ScanState = RISE_KINFE_STATE; +double real_speed = 0; void Automatic_Laser_Scanning() { - CurrentMoveState = Manual_State; //正常速度手动行驶 - CurrentFrontEndState = MANUAL_STEP_UP_STATE; //刀上升至最高点 - StrongGrindingMachineCurrentState = STRONG_GRINDING_MACHINE_HALT_STATE; //刀具不转动 - knife_descent_height = 0; // 这里是初始化为一个合理值防止,用于标记执行过扫描 - - int32_t a = GV.ZHR29_200_measure_results.laser_sensor_1_measure_distance; - int32_t b = GV.ZHR29_200_measure_results.laser_sensor_2_measure_distance; - int32_t c = GV.ZHR29_200_measure_results.laser_sensor_3_measure_distance; + static int OnceFlag = 1; - int32_t max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c); + if (OnceFlag) + { + + OnceFlag = 0; + } - MaxLaserSensor = (max > MaxLaserSensor) ? max : MaxLaserSensor; // 取出激光雷达最大值 + if(GV.MK32_Key.CH7_SD == -1000) + { + StrongGrindingMachineCurrentState = STRONG_GRINDING_MACHINE_HALT_STATE; //刀具不转动 + + int32_t a = GV.ZHR29_200_measure_results.laser_sensor_1_measure_distance; + int32_t b = GV.ZHR29_200_measure_results.laser_sensor_2_measure_distance; + int32_t c = GV.ZHR29_200_measure_results.laser_sensor_3_measure_distance; + + int32_t max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c); + + MaxLaserSensor = (max > MaxLaserSensor) ? max : MaxLaserSensor; // 取出激光雷达最大值 + + if (RISE_KINFE_STATE == ScanState) + { + CurrentFrontEndState = Manual_UP_STATE; //刀上升至最高点 + if (!Pin2) + { + CurrentFrontEndState = HALT_STATE; //刀上升至最高点 + ScanState == FORWARD_STATE; + } + } + else if (FORWARD_STATE == ScanState) + { + CurrentFrontEndState = HALT_STATE; + double ScanTime = ((double)GV.PV.scan_len / 1000.0) / real_speed * 60000.0; + if (HAL_GetTick() - ScanTimeCount >= (int32_t)ScanTime) + { + CurrentMoveState = Move_HALT; + ScanState = BACKWARD_STATE; + } + else + { + CurrentMoveState = AUTO_FORWARD; + } + } + else if (BACKWARD_STATE == ScanState) + { + CurrentFrontEndState = HALT_STATE; + double ScanTime = ((double)(GV.PV.scan_len + GV.PV.scan_back_len) / 1000.0) / real_speed * 60000.0; + if (HAL_GetTick() - ScanTimeCount >= (int32_t)ScanTime) + { + CurrentMoveState = Move_HALT; + knife_descent_height = 0; // 这里是初始化为一个合理值用于标记执行过扫描 + } + else + { + CurrentMoveState = AUTO_FORWARD; + } + } + } + else + { + ScanTimeCount = HAL_GetTick(); + ScanState = RISE_KINFE_STATE; + } + + } #define knife_rising_height 500 // 自动作业停止后默认上升高度为5mm @@ -454,9 +514,6 @@ void Frontend_Control() } - -double real_speed; - void IV_Control() { real_speed = (Act_Speed*360/100/101/6*3.1415926*0.325); diff --git a/diaoerqiege/diaoerqige_V1.0/app/src/main/java/bsp_PV.proto b/diaoerqiege/diaoerqige_V1.0/app/src/main/java/bsp_PV.proto index 552ea03..8cefd8b 100644 --- a/diaoerqiege/diaoerqige_V1.0/app/src/main/java/bsp_PV.proto +++ b/diaoerqiege/diaoerqige_V1.0/app/src/main/java/bsp_PV.proto @@ -7,4 +7,6 @@ message PV_struct_define{ int32 knife_descending_height = 2; int32 main_axis_speed = 3; int32 step_len = 4; + int32 scan_len = 5; + int32 scan_back_len = 6; }; diff --git a/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/MainActivity.java b/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/MainActivity.java index 8fde547..528dfbd 100644 --- a/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/MainActivity.java +++ b/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/MainActivity.java @@ -4,32 +4,27 @@ import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.text.Editable; -import android.text.InputFilter; -import android.text.TextUtils; import android.text.TextWatcher; import android.view.View; import android.view.WindowManager; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.databinding.DataBindingUtil; -import androidx.databinding.adapters.TextViewBindingAdapter; import com.example.diaoerqiegeapp.databinding.ActivityPolishBinding; import com.example.diaoerqiegeapp.models.BspPV; import com.example.diaoerqiegeapp.models.DisplayPV; -import com.example.diaoerqiegeapp.services.DecimalDigitsInputFilter; import com.example.diaoerqiegeapp.services.ModbusCRC; import com.example.diaoerqiegeapp.services.MyDataHelper; import com.example.diaoerqiegeapp.services.PopupHelper; import com.example.diaoerqiegeapp.services.USBSerialPortHelper; -import com.example.diaoerqiegeapp.services.VideoPlayerHelper; + import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import cn.nodemedia.NodePlayer; public class MainActivity extends AppCompatActivity { public ActivityPolishBinding mainBinding; @@ -78,7 +73,8 @@ public class MainActivity extends AppCompatActivity { .setKnifeDescendingHeight(1) .setMainAxisSpeed(10) .setStepLen(1) - + .setScanLen(200) + .setScanBackLen(10) .build(); // 刀下降高度 @@ -123,6 +119,34 @@ public class MainActivity extends AppCompatActivity { } + // 工作距离 + String scan_len = mainBinding.scanLen.getText().toString(); + try { + if( scan_len.isEmpty() ) {_toSendPV = _toSendPV.toBuilder().setScanLen(200).build();} + + else { _toSendPV = _toSendPV.toBuilder() + .setScanLen(Integer.parseInt(scan_len)).build(); + } + } + catch (Exception e) + { + + } + + // 安全距离 + String scan_back_len = mainBinding.scanBackLen.getText().toString(); + try { + if( scan_back_len.isEmpty() ) {_toSendPV = _toSendPV.toBuilder().setScanBackLen(10).build();} + + else { _toSendPV = _toSendPV.toBuilder() + .setScanBackLen(Integer.parseInt(scan_back_len)).build(); + } + } + catch (Exception e) + { + + } + if(_Operate_Mode_Call_Value.equals("手动作业")) { _toSendPV = _toSendPV.toBuilder().setRobotOperationMode(1).build(); diff --git a/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/models/BspPV.java b/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/models/BspPV.java index d65ea9c..6060902 100644 --- a/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/models/BspPV.java +++ b/diaoerqiege/diaoerqige_V1.0/app/src/main/java/com/example/diaoerqiegeapp/models/BspPV.java @@ -52,6 +52,18 @@ public final class BspPV { * @return The stepLen. */ int getStepLen(); + + /** + * int32 scan_len = 5; + * @return The scanLen. + */ + int getScanLen(); + + /** + * int32 scan_back_len = 6; + * @return The scanBackLen. + */ + int getScanBackLen(); } /** * Protobuf type {@code PV_struct_define} @@ -134,6 +146,28 @@ public final class BspPV { return stepLen_; } + public static final int SCAN_LEN_FIELD_NUMBER = 5; + private int scanLen_ = 0; + /** + * int32 scan_len = 5; + * @return The scanLen. + */ + @java.lang.Override + public int getScanLen() { + return scanLen_; + } + + public static final int SCAN_BACK_LEN_FIELD_NUMBER = 6; + private int scanBackLen_ = 0; + /** + * int32 scan_back_len = 6; + * @return The scanBackLen. + */ + @java.lang.Override + public int getScanBackLen() { + return scanBackLen_; + } + private byte memoizedIsInitialized = -1; @java.lang.Override public final boolean isInitialized() { @@ -160,6 +194,12 @@ public final class BspPV { if (stepLen_ != 0) { output.writeInt32(4, stepLen_); } + if (scanLen_ != 0) { + output.writeInt32(5, scanLen_); + } + if (scanBackLen_ != 0) { + output.writeInt32(6, scanBackLen_); + } getUnknownFields().writeTo(output); } @@ -185,6 +225,14 @@ public final class BspPV { size += com.google.protobuf.CodedOutputStream .computeInt32Size(4, stepLen_); } + if (scanLen_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(5, scanLen_); + } + if (scanBackLen_ != 0) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(6, scanBackLen_); + } size += getUnknownFields().getSerializedSize(); memoizedSize = size; return size; @@ -208,6 +256,10 @@ public final class BspPV { != other.getMainAxisSpeed()) return false; if (getStepLen() != other.getStepLen()) return false; + if (getScanLen() + != other.getScanLen()) return false; + if (getScanBackLen() + != other.getScanBackLen()) return false; if (!getUnknownFields().equals(other.getUnknownFields())) return false; return true; } @@ -227,6 +279,10 @@ public final class BspPV { hash = (53 * hash) + getMainAxisSpeed(); hash = (37 * hash) + STEP_LEN_FIELD_NUMBER; hash = (53 * hash) + getStepLen(); + hash = (37 * hash) + SCAN_LEN_FIELD_NUMBER; + hash = (53 * hash) + getScanLen(); + hash = (37 * hash) + SCAN_BACK_LEN_FIELD_NUMBER; + hash = (53 * hash) + getScanBackLen(); hash = (29 * hash) + getUnknownFields().hashCode(); memoizedHashCode = hash; return hash; @@ -362,6 +418,8 @@ public final class BspPV { knifeDescendingHeight_ = 0; mainAxisSpeed_ = 0; stepLen_ = 0; + scanLen_ = 0; + scanBackLen_ = 0; return this; } @@ -407,6 +465,12 @@ public final class BspPV { if (((from_bitField0_ & 0x00000008) != 0)) { result.stepLen_ = stepLen_; } + if (((from_bitField0_ & 0x00000010) != 0)) { + result.scanLen_ = scanLen_; + } + if (((from_bitField0_ & 0x00000020) != 0)) { + result.scanBackLen_ = scanBackLen_; + } } @java.lang.Override @@ -433,6 +497,12 @@ public final class BspPV { if (other.getStepLen() != 0) { setStepLen(other.getStepLen()); } + if (other.getScanLen() != 0) { + setScanLen(other.getScanLen()); + } + if (other.getScanBackLen() != 0) { + setScanBackLen(other.getScanBackLen()); + } this.mergeUnknownFields(other.getUnknownFields()); onChanged(); return this; @@ -479,6 +549,16 @@ public final class BspPV { bitField0_ |= 0x00000008; break; } // case 32 + case 40: { + scanLen_ = input.readInt32(); + bitField0_ |= 0x00000010; + break; + } // case 40 + case 48: { + scanBackLen_ = input.readInt32(); + bitField0_ |= 0x00000020; + break; + } // case 48 default: { if (!super.parseUnknownField(input, extensionRegistry, tag)) { done = true; // was an endgroup tag @@ -624,6 +704,70 @@ public final class BspPV { return this; } + private int scanLen_ ; + /** + * int32 scan_len = 5; + * @return The scanLen. + */ + @java.lang.Override + public int getScanLen() { + return scanLen_; + } + /** + * int32 scan_len = 5; + * @param value The scanLen to set. + * @return This builder for chaining. + */ + public Builder setScanLen(int value) { + + scanLen_ = value; + bitField0_ |= 0x00000010; + onChanged(); + return this; + } + /** + * int32 scan_len = 5; + * @return This builder for chaining. + */ + public Builder clearScanLen() { + bitField0_ = (bitField0_ & ~0x00000010); + scanLen_ = 0; + onChanged(); + return this; + } + + private int scanBackLen_ ; + /** + * int32 scan_back_len = 6; + * @return The scanBackLen. + */ + @java.lang.Override + public int getScanBackLen() { + return scanBackLen_; + } + /** + * int32 scan_back_len = 6; + * @param value The scanBackLen to set. + * @return This builder for chaining. + */ + public Builder setScanBackLen(int value) { + + scanBackLen_ = value; + bitField0_ |= 0x00000020; + onChanged(); + return this; + } + /** + * int32 scan_back_len = 6; + * @return This builder for chaining. + */ + public Builder clearScanBackLen() { + bitField0_ = (bitField0_ & ~0x00000020); + scanBackLen_ = 0; + onChanged(); + return this; + } + // @@protoc_insertion_point(builder_scope:PV_struct_define) } @@ -689,11 +833,12 @@ public final class BspPV { descriptor; static { java.lang.String[] descriptorData = { - "\n\014bsp_PV.proto\"|\n\020PV_struct_define\022\034\n\024ro" + - "bot_operation_mode\030\001 \001(\005\022\037\n\027knife_descen" + - "ding_height\030\002 \001(\005\022\027\n\017main_axis_speed\030\003 \001" + - "(\005\022\020\n\010step_len\030\004 \001(\005B%\n!com.example.diao" + - "erqiegeapp.modelsP\000b\006proto3" + "\n\014bsp_PV.proto\"\245\001\n\020PV_struct_define\022\034\n\024r" + + "obot_operation_mode\030\001 \001(\005\022\037\n\027knife_desce" + + "nding_height\030\002 \001(\005\022\027\n\017main_axis_speed\030\003 " + + "\001(\005\022\020\n\010step_len\030\004 \001(\005\022\020\n\010scan_len\030\005 \001(\005\022" + + "\025\n\rscan_back_len\030\006 \001(\005B%\n!com.example.di" + + "aoerqiegeapp.modelsP\000b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, @@ -704,7 +849,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[] { "RobotOperationMode", "KnifeDescendingHeight", "MainAxisSpeed", "StepLen", }); + new java.lang.String[] { "RobotOperationMode", "KnifeDescendingHeight", "MainAxisSpeed", "StepLen", "ScanLen", "ScanBackLen", }); descriptor.resolveAllFeaturesImmutable(); } diff --git a/diaoerqiege/diaoerqige_V1.0/app/src/main/res/layout/activity_polish.xml b/diaoerqiege/diaoerqige_V1.0/app/src/main/res/layout/activity_polish.xml index 48a0a90..e48994e 100644 --- a/diaoerqiege/diaoerqige_V1.0/app/src/main/res/layout/activity_polish.xml +++ b/diaoerqiege/diaoerqige_V1.0/app/src/main/res/layout/activity_polish.xml @@ -11,559 +11,715 @@ android:orientation="vertical"> + + + + + - + android:layout_marginHorizontal="4dp" + android:layout_marginVertical="12dp" + android:layout_weight="1" + android:background="@drawable/orange_rounded_rectangle" + android:orientation="vertical"> + + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1"> + + + + + + - - - - + + + > - + + + + - > - - - - + + + + + + + + - - - - - - + + + > - + + + + - > - - - - - + + + > - + + + + - > - - - - + + + > - + + + + - > - - - - + + + > - + + + + - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1"> + + - - - - + android:layout_margin="4dp" + android:orientation="horizontal"> - + android:layout_gravity="center" + android:layout_weight="1" + android:gravity="left|center" + android:text="@string/OperateMode" + android:textColor="@color/dark_ink_blue" + android:textSize="15dp" + android:textStyle="bold" /> + + + + + + + + - + - - + + + + + + + - - - + - + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + - android:layout_width="0dp" - android:layout_height="match_parent" - android:layout_weight="1" - android:background="@drawable/rounded_edittext" - android:gravity="center" - android:imeOptions="actionDone" - android:text="mm" - android:textColor="@color/dark_ink_blue" - android:textCursorDrawable="@drawable/my_cursor" - android:textSize="15dp" /> - + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + - - - - + android:orientation="horizontal"> - - - - - - - + + + + + + - - - + + + - + - - - + + + + + android:orientation="horizontal"> @@ -623,17 +784,17 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - -