SQL 错误 [42803]: An expression starting with "COM_ID" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified.. SQLCODE=-119, SQLSTATE=42803, DRIVER=4.26.14

时间: 2025-05-24 08:26:27 浏览: 14
### 关于 SQL 错误 42803 的解决方案 错误 `42803` 表明在查询中,某些列未被包含在 `GROUP BY` 子句中或者这些列不是聚合函数的一部分。此问题通常发生在启用了 `sql_mode=only_full_group_by` 的环境中。 #### 启用 `ONLY_FULL_GROUP_BY` 模式的背景 当数据库服务器运行在 `sql_mode=only_full_group_by` 下时,任何出现在 `SELECT` 列表、`HAVING` 子句或 `ORDER BY` 子句中的列都必须满足以下条件之一: 1. 它们显式地包含在 `GROUP BY` 子句中。 2. 它们作为聚合函数(如 `SUM()`、`COUNT()` 等)的结果存在。 如果违反上述规则,则会触发类似于 `[Err] 1055` 或者 `42803` 的错误消息[^1]。 --- #### 解决方案一:调整 `GROUP BY` 子句 可以通过修改 `GROUP BY` 来解决问题。假设当前的查询如下: ```sql SELECT COM_ID, Name, COUNT(*) FROM CompanyTable GROUP BY COM_ID; ``` 在这种情况下,由于 `Name` 并未参与分组操作也未通过聚合函数处理,因此会产生错误。可以将所有非聚合字段加入到 `GROUP BY` 中来修复该问题: ```sql SELECT COM_ID, Name, COUNT(*) FROM CompanyTable GROUP BY COM_ID, Name; ``` 这样做的原理在于确保每个选定的非聚合字段都被明确指定为分组依据[^2]。 --- #### 解决方案二:使用聚合函数替代具体值 另一种方法是对那些无法放入 `GROUP BY` 的字段应用合适的聚合函数。例如,在上面的例子中可以用 `MIN(Name)` 替代原始的 `Name` 字段定义: ```sql SELECT COM_ID, MIN(Name), COUNT(*) FROM CompanyTable GROUP BY COM_ID; ``` 这里选择了最小的名字 (`MIN`) 进行展示;当然也可以根据实际需求选用其他类型的汇总逻辑比如最大值(`MAX`)等[^3]。 --- #### 解决方案三:禁用 ONLY_FULL_GROUP_BY 设置 虽然不推荐更改默认的安全配置模式,但如果确实需要绕过这个限制,可通过临时关闭 `ONLY_FULL_GROUP_BY` 实现目标。注意这种方式可能带来数据一致性风险并影响性能表现: 执行命令更新 session-level 参数即可生效本次连接期间有效改变行为方式而无需重启服务端程序本身: ```sql SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); ``` 之后再尝试原有问题语句应该不会再报错了但是请谨慎考虑长期维持这样的状态是否合理以及潜在后果如何评估[^4]。 --- ### 总结 针对 SQL 错误 42803 (COM_ID not specified in GROUP BY clause),有三种主要解决途径可供选择——扩展 `GROUP BY` 范围至涵盖全部独立变量、改写查询结构让争议项成为某种形式上的统计量或者是暂时解除严格控制下的分组验证机制约束。每种策略都有其适用场景,请结合具体情况选取最恰当的一种实施修正措施。 ---
阅读全文

相关推荐

OF/********************************************************************************************************************* Copyright (c) 2020 RoboSense All rights reserved By downloading, copying, installing or using the software you agree to this license. If you do not agree to this license, do not download, install, copy or use the software. License Agreement For RoboSense LiDAR SDK Library (3-clause BSD License) Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the names of the RoboSense, nor Suteng Innovation Technology, nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *********************************************************************************************************************/ #include "manager/node_manager.hpp" #include <rs_driver/macro/version.hpp> #include <signal.h> #ifdef ROS_FOUND #include <ros/ros.h> #include <ros/package.h> #elif ROS2_FOUND #include <rclcpp/rclcpp.hpp> #endif using namespace robosense::lidar; #ifdef ROS2_FOUND std::mutex g_mtx; std::condition_variable g_cv; #endif static void sigHandler(int sig) { RS_MSG << "RoboSense-LiDAR-Driver is stopping....." << RS_REND; #ifdef ROS_FOUND ros::shutdown(); #elif ROS2_FOUND g_cv.notify_all(); #endif } /////////////////////////////////////////////////////////////////////////////////////////////// static std::string pcd_name_prefix = ""; void SetPCDNamePrefix(const std::string& prefix) { RS_INFO << "------------------------------------------------------" << RS_REND; RS_INFO << "Set PCD Name Prefix: " << prefix << RS_REND; pcd_name_prefix = prefix; RS_INFO << "------------------------------------------------------" << RS_REND; } const std::string& GetPCDNamePrefix() { // RS_INFO << "Use PCD Name Prefix: " << pcd_name_prefix << RS_REND; return pcd_name_prefix; } /////////////////////////////////////////////////////////////////////////////////////////////// static std::string pcd_file_path = ""; void SetPCDFilePath(const std::string& path) { RS_INFO << "------------------------------------------------------" << RS_REND; RS_INFO << "Set PCD Dir: " << path << RS_REND; pcd_file_path = path; RS_INFO << "------------------------------------------------------" << RS_REND; } const std::string& GetPCDFilePath() { // RS_INFO << "Use PCD Dir: " << pcd_file_path << RS_REND; return pcd_file_path; } /////////////////////////////////////////////////////////////////////////////////////////////// void StringSplit(const std::string& str, const char split_char, std::vector<std::string>& res) { std::istringstream iss(str); std::string token; while(getline(iss, token, split_char)) { res.push_back(std::move(token)); } } const std::size_t LIDAR_INDEX_IN_PCAP_FILE = 4; /////////////////////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { signal(SIGINT, sigHandler); ///< bind ctrl+c signal with the sigHandler function RS_TITLE << "********************************************************" << RS_REND; RS_TITLE << "********** **********" << RS_REND; RS_TITLE << "********** RSLidar_SDK Version: v" << RSLIDAR_VERSION_MAJOR << "." << RSLIDAR_VERSION_MINOR << "." << RSLIDAR_VERSION_PATCH << " **********" << RS_REND; RS_TITLE << "********** **********" << RS_REND; RS_TITLE << "********************************************************" << RS_REND; #ifdef ROS_FOUND ros::init(argc, argv, "rslidar_sdk_node", ros::init_options::NoSigintHandler); #elif ROS2_FOUND rclcpp::init(argc, argv); #endif std::string config_path; #ifdef RUN_IN_ROS_WORKSPACE config_path = ros::package::getPath("rslidar_sdk"); #else config_path = (std::string)PROJECT_PATH; #endif config_path += "/config/"; #ifdef ROS_FOUND ros::NodeHandle priv_hh("~"); std::string pcap_file; std::string dest_pcd_dir; priv_hh.param("pcap_file", pcap_file, std::string("")); priv_hh.param("dest_pcd_dir", dest_pcd_dir, std::string("")); #elif ROS2_FOUND std::shared_ptr<rclcpp::Node> nd = rclcpp::Node::make_shared("param_handle"); std::string pcap_file = nd->declare_parameter<std::string>("pcap_file", ""); std::string dest_pcd_dir = nd->declare_parameter<std::string>("dest_pcd_dir", ""); #endif // #if defined(ROS_FOUND) || defined(ROS2_FOUND) // if (!path.empty()) // { // config_path = path; // } // #endif std::string lidar_name = ""; std::vector<std::string> path_nodes{}; StringSplit(pcap_file, '/', path_nodes); std::vector<std::string> filename_segs{}; std::vector<std::string> token_res{}; if (path_nodes.size() > 0) { StringSplit(path_nodes[path_nodes.size()-1], '.', filename_segs); if (filename_segs.size() > 0) { StringSplit(filename_segs[0], '_', token_res); } else { RS_ERROR << "The lidar name in pcap file is not specified: [" << pcap_file << "] is wrong. Please check." << RS_REND; return -1; } } if (token_res.size() <= LIDAR_INDEX_IN_PCAP_FILE) { RS_ERROR << "The lidar name in pcap file is not specified: [" << pcap_file << "] is wrong. Please check." << RS_REND; return -1; } else { lidar_name = token_res[LIDAR_INDEX_IN_PCAP_FILE]; std::stringstream ss; for (std::size_t i = 0; i <= LIDAR_INDEX_IN_PCAP_FILE; i++) { ss << token_res[i] << "_"; } SetPCDNamePrefix(ss.str()); } std::stringstream ss; ss << "config-" << lidar_name << ".yaml"; config_path = config_path + ss.str(); if (dest_pcd_dir.empty()) { RS_ERROR << "The destination pcd output dir is not specified: [" << dest_pcd_dir << "] is wrong. Please check." << RS_REND; return -1; } else { SetPCDFilePath(dest_pcd_dir); } SourceDriverPCAPPath::SetPCAPFilePath(pcap_file); YAML::Node config; try { config = YAML::LoadFile(config_path); RS_INFO << "--------------------------------------------------------" << RS_REND; RS_INFO << "Config loaded from PATH:" << RS_REND; RS_INFO << config_path << RS_REND; RS_INFO << "--------------------------------------------------------" << RS_REND; } catch (...) { RS_ERROR << "The format of config file " << config_path << " is wrong. Please check (e.g. indentation)." << RS_REND; return -1; } std::shared_ptr<NodeManager> demo_ptr = std::make_shared<NodeManager>(); demo_ptr->init(config); demo_ptr->start(); RS_MSG << "RoboSense-LiDAR-Driver is running....." << RS_REND; #ifdef ROS_FOUND ros::spin(); #elif ROS2_FOUND std::unique_lock<std::mutex> lck(g_mtx); g_cv.wait(lck); #endif return 0; }

/******************************************************************************* *BSD 3-Clause License * *Copyright (c) 2016-2023, Mech-Mind Robotics *All rights reserved. * *Redistribution and use in source and binary forms, with or without *modification, are permitted provided that the following conditions are met: * *1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * *2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * *3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ #pragma once #include <memory> #include <string> #include "common/StatusCode.h" namespace mmind::dl { /** * @brief Defines the Image. */ struct MMIND_DL_SDK_EXPORT MMindImage { /** * @brief Creates an image from its path. * @param [in] imagePath Image storage path. * @return See @ref StatusCode for details. */ StatusCode createFromPath(const std::string& imagePath); /** * @brief Visualizes an image. * @param [in] winName The window name for visualizing an image. * @return See @ref StatusCode for details. * @note The size of the image display window equals to that of the image. */ StatusCode show(const std::string& winName); /** * @brief Saves the image to a specified directory. * @param [in] savePath The path to save the image. * @return See @ref StatusCode for details. */ StatusCode save(const std::string& savePath); /** * @brief Releases the memory of the image. */ ~MMindImage(); int width = 0; ///< The width of the image. int height = 0; ///< The height of the image. int channel = 0; ///< The number of channels in the image. int depth = 0; ///< The depth of the image. std::shared_ptr<unsigned char> data = nullptr; ///< The pointer of the image data. }; } // namespace mmind::dl 这里面的析构函数还是虚函数,不需要绑定吗? ~MMindImage();

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * *
© Copyright (c) 2025 STMicroelectronics. * All rights reserved.
* * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "tim.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "stdio.h" #include "time.h" #include "stdlib.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ int num_tim1; float distance; int first; void Motor_PWM_Start(void) { //PB6 HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_1); //PB7 HAL_TIM_PWM_Start(&htim4,TIM_CHANNEL_2); } void SR04_Work(void) { //PA15 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_15,1); HAL_Delay(1); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_15,0); HAL_Delay(60); } void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { if(GPIO_Pin == GPIO_PIN_12) { if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_12)==1) { HAL_TIM_Base_Start(&htim1); __HAL_TIM_SET_COUNTER(&htim1,0); } else if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_12)==0) { HAL_TIM_Base_Stop(&htim1); num_tim1 = __HAL_TIM_GET_COUNTER(&htim1); distance=(float)num_tim1 * 340 / 2 * 100 * 0.000001; } } } int fputc(int ch, FILE* stream) { HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 5); return ch; } void Car_Straight(int speed) { //left reversal //PB7(PWMA),PB8(AIN1),PB9(AIN2):101 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,0); HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,1); __HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_2,speed); //right reversal //PB6(PWMB),PB5(BIN1),PB4(BIN2):101 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_5,0); HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,1); __HAL_TIM_SET_COMPARE(&htim4,TIM_CHANNEL_1,speed); } //back void Car_Back(int speed) { // PB7(PWMA),PB8(AIN1),PB9(AIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed); // PB6(PWMB),PB5(BIN1),PB4(BIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed); } //turn right void Car_Right(int speed) { // PB7(PWMA),PB8(AIN1),PB9(AIN2):101 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 1); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed); // PB6(PWMB),PB5(BIN1),PB4(BIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed); } //turn left void Car_Left(int speed) { // PB7(PWMA),PB8(AIN1),PB9(AIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed); // PB6(PWMB),PB5(BIN1),PB4(BIN2):101 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed); } //stop void Car_Stop(void) { // PB7(PWMA),PB8(AIN1),PB9(AIN2):000 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, 0); // PB6(PWMB),PB5(BIN1),PB4(BIN2):000 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, 0); } // S void Car_Curve(int speed) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 1); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed * 0.5); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed); HAL_Delay(1800); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, 0); HAL_Delay(500); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 1); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 1); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed * 0.5); HAL_Delay(1800); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, 0); HAL_Delay(500); // PB7(PWMA),PB8(AIN1),PB9(AIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed); // PB6(PWMB),PB5(BIN1),PB4(BIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed*0.5); HAL_Delay(1800); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, 0); HAL_Delay(500); // PB7(PWMA),PB8(AIN1),PB9(AIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_2, speed*0.5); // PB6(PWMB),PB5(BIN1),PB4(BIN2):110 HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, 1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, 0); __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, speed); HAL_Delay(1800); } void SG90_Control(int angle) { int value_compare=0; value_compare=11*angle+500; __HAL_TIM_SET_COMPARE(&htim1,TIM_CHANNEL_4,value_compare); } /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_TIM4_Init(); MX_TIM1_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ Motor_PWM_Start(); srand(HAL_GetTick()); HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_4); SG90_Control(90); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { // 1. ?? 2s(????? 500) SG90_Control(10); HAL_Delay(500); SG90_Control(45); HAL_Delay(500); SG90_Control(90); HAL_Delay(500); SG90_Control(135); HAL_Delay(500); SG90_Control(180); HAL_Delay(500); SR04_Work(); printf("num=%d\n",num_tim1); printf("distance=%.2f\n",distance); HAL_Delay(1000); int turn = rand() % 2; SR04_Work(); HAL_Delay(50); if(first==0) { first++; continue; } if (distance >= 40.0f) { Car_Straight(400); } else { Car_Stop(); HAL_Delay(200); Car_Back(400); HAL_Delay(300); Car_Stop(); HAL_Delay(200); if(!turn) { Car_Left(400); } else { Car_Right(400); } HAL_Delay(400); Car_Stop(); HAL_Delay(200); } HAL_Delay(100); } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 超声波+舵机+电机驱动,实现综合避障

/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * *
© Copyright (c) 2023 STMicroelectronics. * All rights reserved.
* * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "usart.h" #include "gpio.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ uint8_t Humen_Infr_Status = 0; uint8_t Humen_Infr_Flag = 0; uint32_t change_count = 0; // ??????? /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { Humen_Infr_Status = HAL_GPIO_ReadPin(GPIOG, GPIO_PIN_2); if(Humen_Infr_Status != Humen_Infr_Flag) { Humen_Infr_Flag = Humen_Infr_Status; change_count++; // ????? printf("Humen_Infr Sensor : %d\r\n", Humen_Infr_Status); printf("Humen_Infr_sensor is OK!\r\n"); printf("µ±Ç°ÊǵÚ%lu´Î±ä»¯\r\n", change_count); // ???????? } HAL_Delay(10); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 4; RCC_OscInitStruct.PLL.PLLN = 168; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 修改此代码,加入计时功能。设置一个计时器变量,当状态值为1时,每隔1000毫秒输出一次:“当前状态已持续x ms。”否则计时器归零。

最新推荐

recommend-type

微软内部资料-SQL性能优化3

An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...
recommend-type

网络计划基本知识.ppt

网络计划基本知识.ppt
recommend-type

第一章装饰工程项目管理.ppt

第一章装饰工程项目管理.ppt
recommend-type

matlab控制系统计算机辅助设计-长安大学.ppt

matlab控制系统计算机辅助设计-长安大学.ppt
recommend-type

Evc Sql CE 程序开发实践与样例代码分享

在详细解释标题、描述和标签中提及的知识点之前,需要指出“压缩包子文件的文件名称列表”中的“8”可能是不完整的上下文信息。由于缺乏具体的文件列表内容,我们将主要集中在如何理解“Evc Sql CE 程序样例代码”这一主题。 标题“Evc Sql CE 程序样例代码”直接指向一个程序开发样例代码,其中“Evc”可能是某种环境或工具的缩写,但由于没有更多的上下文信息,很难精确地解释这个缩写指的是什么。不过,“Sql CE”则明确地指向了“SQL Server Compact Edition”,它是微软推出的一个轻量级数据库引擎,专为嵌入式设备和小型应用程序设计。 ### SQL Server Compact Edition (SQL CE) SQL Server Compact Edition(简称SQL CE)是微软公司提供的一个嵌入式数据库解决方案,它支持多种平台和编程语言。SQL CE适合用于资源受限的环境,如小型应用程序、移动设备以及不需要完整数据库服务器功能的场合。 SQL CE具备如下特点: - **轻量级**: 轻便易用,对系统资源占用较小。 - **易于部署**: 可以轻松地将数据库文件嵌入到应用程序中,无需单独安装。 - **支持多平台**: 能够在多种操作系统上运行,包括Windows、Windows CE和Windows Mobile等。 - **兼容性**: 支持标准的SQL语法,并且在一定程度上与SQL Server数据库系统兼容。 - **编程接口**: 提供了丰富的API供开发者进行数据库操作,支持.NET Framework和本机代码。 ### 样例代码的知识点 “Evc Sql CE 程序样例代码”这部分信息表明,存在一些示例代码,这些代码可以指导开发者如何使用SQL CE进行数据库操作。样例代码一般会涵盖以下几个方面: 1. **数据库连接**: 如何创建和管理到SQL CE数据库的连接。 2. **数据操作**: 包括数据的增删改查(CRUD)操作,这些是数据库操作中最基本的元素。 3. **事务处理**: 如何在SQL CE中使用事务,保证数据的一致性和完整性。 4. **数据表操作**: 如何创建、删除数据表,以及修改表结构。 5. **数据查询**: 利用SQL语句查询数据,包括使用 SELECT、JOIN等语句。 6. **数据同步**: 如果涉及到移动应用场景,可能需要了解如何与远程服务器进行数据同步。 7. **异常处理**: 在数据库操作中如何处理可能发生的错误和异常。 ### 标签中的知识点 标签“Evc Sql CE 程序样例代码”与标题内容基本一致,强调了这部分内容是关于使用SQL CE的示例代码。标签通常用于标记和分类信息,方便在搜索引擎或者数据库中检索和识别特定内容。在实际应用中,开发者可以根据这样的标签快速找到相关的样例代码,以便于学习和参考。 ### 总结 根据标题、描述和标签,我们可以确定这篇内容是关于SQL Server Compact Edition的程序样例代码。由于缺乏具体的代码文件名列表,无法详细分析每个文件的内容。不过,上述内容已经概述了SQL CE的关键特性,以及开发者在参考样例代码时可能关注的知识点。 对于希望利用SQL CE进行数据库开发的程序员来说,样例代码是一个宝贵的资源,可以帮助他们快速理解和掌握如何在实际应用中运用该数据库技术。同时,理解SQL CE的特性、优势以及编程接口,将有助于开发者设计出更加高效、稳定的嵌入式数据库解决方案。
recommend-type

【浪潮FS6700交换机配置实战】:生产环境快速部署策略与技巧

# 1. 浪潮FS6700交换机概述 浪潮FS6700交换机是一款高端、具备高密度端口的全千兆交换机。它采用模块化设计,支持万兆上行,可提供灵活的端口组合和高带宽解决方案,满足了企业网络对于高性能、高可靠性的需求。浪潮FS6700交换机通常部署在企业网络的核心层或汇聚层,不仅提供强劲的网络数据交换能力,而且支持丰富的路由协议和安全特性,为中大型网络构建提供了强有力的保障。 接下来,我们将深
recommend-type

YOLO11训练批次参考

<think>我们正在讨论YOLOv11的训练批次设置。首先,需要明确的是,截至2023年10月,官方并没有发布YOLOv11版本。YOLO系列的最新版本是YOLOv8(由Ultralytics发布)。因此,这里可能指的是YOLO的某个变体或非官方版本。不过,我们可以基于YOLO系列的一般训练实践来讨论训练批次(batch size)的设置。 训练批次(batch size)是指在训练神经网络时,每次迭代中用于计算梯度并更新权重的样本数量。设置合适的batch size对训练效果和速度有重要影响。 ### 影响batch size选择的因素: 1. **硬件限制**:显存大小是主要限制因素
recommend-type

数据库考试复习必备五套习题精讲

根据给定的文件信息,本文将详细解释数据库习题相关知识点。首先,从标题中我们可以得知,该文件为数据库习题集,包含五套习题卷,非常适合用来准备考试。由于文件描述中提到考完试后才打算分享,说明这些习题具有一定的质量和难度,可以作为考试前的必备材料。 首先,我们来解释“数据库”这一核心概念。数据库是存储、管理、处理和检索信息的系统,它能够帮助我们有效地存储大量的数据,并在需要的时候快速访问。数据库管理系统(DBMS)是负责数据库创建、维护和操作的软件,常见的数据库管理系统包括MySQL、Oracle、Microsoft SQL Server、PostgreSQL和SQLite等。 数据库习题通常包括以下知识点: 1. 数据库设计:设计数据库时需要考虑实体-关系模型(ER模型)、规范化理论以及如何设计表结构。重点包括识别实体、确定实体属性、建立实体之间的关系以及表之间的关联。规范化是指将数据库表结构进行合理化分解,以减少数据冗余和提高数据一致性。 2. SQL语言:结构化查询语言(SQL)是用于管理数据库的标准计算机语言,它包括数据查询、数据操纵、数据定义和数据控制四个方面的功能。对于数据库习题来说,重点会涉及到以下SQL语句: - SELECT:用于从数据库中查询数据。 - INSERT、UPDATE、DELETE:用于向数据库中插入、更新或删除数据。 - CREATE TABLE、ALTER TABLE、DROP TABLE:用于创建、修改或删除表结构。 - JOIN:用于连接两个或多个表来查询跨越表的数据。 - GROUP BY 和 HAVING:用于对数据进行分组统计和筛选。 -事务处理:包括事务的ACID属性(原子性、一致性、隔离性、持久性)等。 3. 数据库操作:涉及实际操作数据库的过程,包括数据导入导出、备份与恢复、索引创建与优化等。这些内容能够帮助理解如何高效地管理数据。 4. 数据库安全:保障数据库不受未授权访问和破坏的机制,例如用户权限管理、视图、存储过程等安全措施。 5. 数据库优化:如何提升数据库的性能,包括查询优化、数据库配置优化、索引策略、系统资源监控等。 6. 数据库应用开发:如何利用数据库在应用程序中实现数据的持久化存储,如数据库连接、事务管理、数据访问对象(DAO)设计模式等。 7. 高级主题:涉及到复杂查询、数据库触发器、存储过程的编写和优化,以及可能包含的特定数据库系统的特定特性(如Oracle的PL/SQL编程等)。 由于文件名称列表只提供“数据库习题”这一个信息点,我们无法得知具体的习题内容和难度,但是可以肯定的是,这份习题集应该覆盖了上述所提到的知识点。对于考生来说,这些习题将帮助他们巩固理论知识,并且提高解决实际问题的能力,是考试前准备的有力工具。 在准备数据库相关的考试时,建议先从基础概念开始复习,然后逐步过渡到SQL语法和数据库设计的实践操作。在习题练习中,注意不要仅限于死记硬背,更重要的是理解每一个操作背后的逻辑和原理。如果可能的话,实际操作一个数据库,将理论知识应用到实践中去,这会帮助你更加深刻地理解数据库的工作机制。最后,反复练习模拟题,可以帮助你熟悉考试的题型和难度,提高考试时的应试技巧。
recommend-type

【浪潮FS6700交换机故障诊断与排除】:掌握这些方法,让你的网络稳定如初

# 1. 浪潮FS6700交换机故障诊断基础知识 在本章中,我们将探讨浪潮FS6700交换机故障诊断的基础知识,为后续章节中更深层次的理论和实践内容打下坚实的基础。我们将从以下几个方面入手,逐步深化对故障诊断的认识: ## 1.1 交换机故障诊断的重要性 交换机作为网络的核心设备,其稳定性和性能直接影响着整个网络的运行效率。因此,准确且快速地诊断和解决交换机故障是网
recommend-type

JVM内存整体结构图

<think>我们正在处理一个关于JVM内存结构的问题,用户要求获取详细图解。由于我们无法直接发送图片,但可以通过文字描述和引用相关资源来满足需求。 根据引用内容,我们可以总结JVM内存结构的主要部分: 1. 线程栈(Thread Stacks):每个线程创建时分配,存储局部变量和方法调用栈。 2. 堆(Heap):存储所有对象、实例变量和数组,被所有线程共享。堆又分为年轻代(Young Generation)和老年代(Old Generation)。 3. 非堆内存(Non-Heap Memory):包括方法区(Method Area)和运行时常量池(Runtime Constant