Hello,
I am newbie in embedded world, but until now I could solve my problems just with searching on internet. Now I cannot solve this problem and this is my first question in this forum. I can write here something very absurd, please ignore them. I will try to do my best to explain my problem.
For this project I am using stm32F407vgt6 MCU, Cubemx (v 5.6.1) , Keilµvision (v 5.29.0.0). (Cubemx pinout will be uploaded as Picture)
I have builded a 4 leg spider with 12 servos with timer 2,3 and timer 4. I am commanding my robot via Bluetooth module(hc-05). Now it can walk and turn right left.
I want to open a interrupt channel (PC13) which is connected to a sensor .
What I want to do;
If I insert a metall dedector to Interrupt channel and robot meets with an metal, I want that robot stops and turn another direction and continue to walk. (Or we can think that when it comes against a wall, infrared sensor will be activated and robot stops and walk another direction). I did not use a analog sensor, instead I have connected with a digital sensor and read the sensor as it is button. I am not working on ADC mode.
I have applied all what I want and start the test.
Attempt 1:
Firstly I wrote just the stand position code in Interrupt function without a delay code as it has seen followingly.
/* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){/* Prevent unused argument(s) compilation warning */UNUSED(GPIO_Pin);/* NOTE: This function Should not be modified, when the callback is needed,the HAL_GPIO_EXTI_Callback could be implemented in the user file*/
htim2.Instance->CCR1 = 185;htim2.Instance->CCR2 = 115;htim2.Instance->CCR3 = 110;htim2.Instance->CCR4 = 180;htim3.Instance->CCR1 = 125;htim3.Instance->CCR2 = 185;htim3.Instance->CCR3 = 180;htim3.Instance->CCR4 = 115;
htim4.Instance->CCR1 = 125;htim4.Instance->CCR2 = 180;htim4.Instance->CCR3 = 190;htim4.Instance->CCR4 = 125;}/* USER CODE END 4 */
Result: The robot stops just a second in stand position and continue to walk suddenly.
Attemp 2: I have thought without a delay function interrupt does not take much time and continue to walk, and wrote turn right code which has too much delay in it.
/* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ /* Prevent unused argument(s) compilation warning */ UNUSED(GPIO_Pin); /* NOTE: This function Should not be modified, when the callback is needed, the HAL_GPIO_EXTI_Callback could be implemented in the user file */ //2. Leg htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 210; HAL_Delay(100); htim2.Instance->CCR2 = 110; HAL_Delay(40); htim2.Instance->CCR2 = 166; HAL_Delay(100); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 185; HAL_Delay(100);
etc...}/* USER CODE END 4 */
Result: If there is a delay code in user code 4, it makes always this result. When interrupt chn is activated, the robot stops moving and take no more command until I reset the MCU.
and later I tried so many other possibilities, but it did not work. (writing the all codes in interrupt function | in while section creating a interrupt button and "if(interruptState){}" etc.)
I kindly need your helps.
What should I do to overcome this problem?
My codes are very very long so I can not write down here but I will give short and important examples of my code at the end of this post.
/* USER CODE BEGIN PV */
char rxMessage[1];
/* USER CODE END PV */
-----------------
/* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2)
etc...
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); /* USER CODE END 2 */
while (1) { /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ if(HAL_UART_Receive(&huart1,(uint8_t *)rxMessage,sizeof(rxMessage),HAL_MAX_DELAY)!=HAL_OK){ Error_Handler(); } if(strncmp(rxMessage,"n",1)==0){
htim2.Instance->CCR1 = 185; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; htim2.Instance->CCR4 = 180; htim3.Instance->CCR1 = 125; htim3.Instance->CCR2 = 185; htim3.Instance->CCR3 = 180; htim3.Instance->CCR4 = 115;
htim4.Instance->CCR1 = 125; htim4.Instance->CCR2 = 180; htim4.Instance->CCR3 = 190; htim4.Instance->CCR4 = 125;
} (This stand and start position of the robot)
Walking
if(strncmp(rxMessage,"i",1)==0){ //Left-Front leg htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 205; HAL_Delay(100); htim2.Instance->CCR2 = 113; htim4.Instance->CCR2 = 176;HAL_Delay(40); htim2.Instance->CCR2 = 85; htim4.Instance->CCR2 = 150; HAL_Delay(100); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 178; HAL_Delay(100);
etc...}
/* USER CODE BEGIN 4 */void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ /* Prevent unused argument(s) compilation warning */ UNUSED(GPIO_Pin); /* NOTE: This function Should not be modified, when the callback is needed, the HAL_GPIO_EXTI_Callback could be implemented in the user file */ }/* USER CODE END 4 */
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>© Copyright (c) 2021 STMicroelectronics. * All rights reserved.</center></h2> * * 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" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "string.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 ---------------------------------------------------------*/ ADC_HandleTypeDef hadc1; TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim4; UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */ char rxMessage[1]; uint16_t interruptState=0; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC1_Init(void); static void MX_TIM2_Init(void); static void MX_TIM3_Init(void); static void MX_TIM4_Init(void); static void MX_USART1_UART_Init(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--------------------------------------------------------*/ /* 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_ADC1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM4_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // if(interruptState==0){ // // htim3.Instance->CCR4 = 110; htim3.Instance->CCR2 = 190; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; // HAL_Delay(40); // htim3.Instance->CCR4 = 105; htim3.Instance->CCR2 = 195; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; // HAL_Delay(40); // htim3.Instance->CCR4 = 100; htim3.Instance->CCR2 = 200; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; // HAL_Delay(40); // htim3.Instance->CCR4 = 95; htim3.Instance->CCR2 = 205; htim3.Instance->CCR1 = 105; htim3.Instance->CCR3 = 200; // HAL_Delay(40); // htim3.Instance->CCR4 = 85; htim3.Instance->CCR2 = 220; htim3.Instance->CCR1 = 90; htim3.Instance->CCR3 = 215; // HAL_Delay(100); // // // htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR1 = 180; htim2.Instance->CCR3 = 105; // HAL_Delay(40); // htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR1 = 175; htim2.Instance->CCR3 = 100; // HAL_Delay(40); // htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 102; htim2.Instance->CCR1 = 170; htim2.Instance->CCR3 = 95; // HAL_Delay(40); // htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 97; htim2.Instance->CCR1 = 165; htim2.Instance->CCR3 = 90; // HAL_Delay(40); // htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 94; htim2.Instance->CCR1 = 160; htim2.Instance->CCR3 = 85; // HAL_Delay(40); // htim2.Instance->CCR4 = 150; htim2.Instance->CCR2 = 90; htim2.Instance->CCR1 = 155; htim2.Instance->CCR3 = 80; // HAL_Delay(100); // // htim3.Instance->CCR2 = 210; htim3.Instance->CCR4 = 90; htim3.Instance->CCR1 = 100; htim3.Instance->CCR3 = 205; // HAL_Delay(40); // htim3.Instance->CCR2 = 200; htim3.Instance->CCR4 = 100; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; // HAL_Delay(40); // htim3.Instance->CCR2 = 195; htim3.Instance->CCR4 = 105; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; // HAL_Delay(40); // htim3.Instance->CCR2 = 190; htim3.Instance->CCR4 = 110; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; // HAL_Delay(40); // htim3.Instance->CCR2 = 185; htim3.Instance->CCR4 = 115; htim3.Instance->CCR1 = 125; htim3.Instance->CCR3 = 180; // HAL_Delay(100); // // //Body turn // // htim2.Instance->CCR1 = 155; htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 93; htim2.Instance->CCR3 = 85; // HAL_Delay(40); // htim2.Instance->CCR1 = 162; htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 95; htim2.Instance->CCR3 = 90; // HAL_Delay(40); // htim2.Instance->CCR1 = 170; htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 100; htim2.Instance->CCR3 = 95; // HAL_Delay(40); // htim2.Instance->CCR1 = 176; htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR3 = 100; // HAL_Delay(40); // htim2.Instance->CCR1 = 180; htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR3 = 105; // HAL_Delay(40); // htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; // HAL_Delay(100); // } if(HAL_UART_Receive(&huart1,(uint8_t *)rxMessage,sizeof(rxMessage),HAL_MAX_DELAY)!=HAL_OK){ Error_Handler(); } if(interruptState){ } if(strncmp(rxMessage,"c",1)==0){ htim2.Instance->CCR1 = 147; htim2.Instance->CCR2 = 155; htim2.Instance->CCR3 = 155; htim2.Instance->CCR4 = 155; htim3.Instance->CCR1 = 155; htim3.Instance->CCR2 = 155; htim3.Instance->CCR3 = 147; htim3.Instance->CCR4 = 147; htim4.Instance->CCR1 = 155; htim4.Instance->CCR2 = 155; htim4.Instance->CCR3 = 155; htim4.Instance->CCR4 = 155; } //fast right if(strncmp(rxMessage,"a",1)==0){ htim3.Instance->CCR4 = 110; htim3.Instance->CCR2 = 190; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR4 = 105; htim3.Instance->CCR2 = 195; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR4 = 100; htim3.Instance->CCR2 = 200; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR4 = 95; htim3.Instance->CCR2 = 205; htim3.Instance->CCR1 = 105; htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR4 = 85; htim3.Instance->CCR2 = 220; htim3.Instance->CCR1 = 90; htim3.Instance->CCR3 = 215; HAL_Delay(100); htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR1 = 180; htim2.Instance->CCR3 = 105; HAL_Delay(40); htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR1 = 175; htim2.Instance->CCR3 = 100; HAL_Delay(40); htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 102; htim2.Instance->CCR1 = 170; htim2.Instance->CCR3 = 95; HAL_Delay(40); htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 97; htim2.Instance->CCR1 = 165; htim2.Instance->CCR3 = 90; HAL_Delay(40); htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 94; htim2.Instance->CCR1 = 160; htim2.Instance->CCR3 = 85; HAL_Delay(40); htim2.Instance->CCR4 = 150; htim2.Instance->CCR2 = 90; htim2.Instance->CCR1 = 155; htim2.Instance->CCR3 = 80; HAL_Delay(100); htim3.Instance->CCR2 = 210; htim3.Instance->CCR4 = 90; htim3.Instance->CCR1 = 100; htim3.Instance->CCR3 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 200; htim3.Instance->CCR4 = 100; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 195; htim3.Instance->CCR4 = 105; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 190; htim3.Instance->CCR4 = 110; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR2 = 185; htim3.Instance->CCR4 = 115; htim3.Instance->CCR1 = 125; htim3.Instance->CCR3 = 180; HAL_Delay(100); //Body turn htim2.Instance->CCR1 = 155; htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 93; htim2.Instance->CCR3 = 85; HAL_Delay(40); htim2.Instance->CCR1 = 162; htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 95; htim2.Instance->CCR3 = 90; HAL_Delay(40); htim2.Instance->CCR1 = 170; htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 100; htim2.Instance->CCR3 = 95; HAL_Delay(40); htim2.Instance->CCR1 = 176; htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR3 = 100; HAL_Delay(40); htim2.Instance->CCR1 = 180; htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR3 = 105; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; HAL_Delay(100); ///////////////////////// htim3.Instance->CCR4 = 110; htim3.Instance->CCR2 = 190; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR4 = 105; htim3.Instance->CCR2 = 195; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR4 = 100; htim3.Instance->CCR2 = 200; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR4 = 95; htim3.Instance->CCR2 = 205; htim3.Instance->CCR1 = 105; htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR4 = 85; htim3.Instance->CCR2 = 220; htim3.Instance->CCR1 = 90; htim3.Instance->CCR3 = 215; HAL_Delay(100); htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR1 = 180; htim2.Instance->CCR3 = 105; HAL_Delay(40); htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR1 = 175; htim2.Instance->CCR3 = 100; HAL_Delay(40); htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 102; htim2.Instance->CCR1 = 170; htim2.Instance->CCR3 = 95; HAL_Delay(40); htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 97; htim2.Instance->CCR1 = 165; htim2.Instance->CCR3 = 90; HAL_Delay(40); htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 94; htim2.Instance->CCR1 = 160; htim2.Instance->CCR3 = 85; HAL_Delay(40); htim2.Instance->CCR4 = 150; htim2.Instance->CCR2 = 90; htim2.Instance->CCR1 = 155; htim2.Instance->CCR3 = 80; HAL_Delay(100); htim3.Instance->CCR2 = 210; htim3.Instance->CCR4 = 90; htim3.Instance->CCR1 = 100; htim3.Instance->CCR3 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 200; htim3.Instance->CCR4 = 100; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 195; htim3.Instance->CCR4 = 105; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 190; htim3.Instance->CCR4 = 110; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR2 = 185; htim3.Instance->CCR4 = 115; htim3.Instance->CCR1 = 125; htim3.Instance->CCR3 = 180; HAL_Delay(100); //Body turn htim2.Instance->CCR1 = 155; htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 93; htim2.Instance->CCR3 = 85; HAL_Delay(40); htim2.Instance->CCR1 = 162; htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 95; htim2.Instance->CCR3 = 90; HAL_Delay(40); htim2.Instance->CCR1 = 170; htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 100; htim2.Instance->CCR3 = 95; HAL_Delay(40); htim2.Instance->CCR1 = 176; htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR3 = 100; HAL_Delay(40); htim2.Instance->CCR1 = 180; htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR3 = 105; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; HAL_Delay(100); /////////////////////////// } //fast left if(strncmp(rxMessage,"x",1)==0){ htim3.Instance->CCR4 = 110; htim3.Instance->CCR2 = 190; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR4 = 105; htim3.Instance->CCR2 = 195; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR4 = 100; htim3.Instance->CCR2 = 200; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR4 = 95; htim3.Instance->CCR2 = 205; htim3.Instance->CCR1 = 105; htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR4 = 85; htim3.Instance->CCR2 = 220; htim3.Instance->CCR1 = 90; htim3.Instance->CCR3 = 215; HAL_Delay(100); htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR1 = 185; htim2.Instance->CCR3 = 115; HAL_Delay(40); htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR1 = 190; htim2.Instance->CCR3 = 120; HAL_Delay(40); htim2.Instance->CCR4 = 185; htim2.Instance->CCR2 = 120; htim2.Instance->CCR1 = 195; htim2.Instance->CCR3 = 125; HAL_Delay(40); htim2.Instance->CCR4 = 190; htim2.Instance->CCR2 = 127; htim2.Instance->CCR1 = 200; htim2.Instance->CCR3 = 130; HAL_Delay(40); htim2.Instance->CCR4 = 195; htim2.Instance->CCR2 = 132; htim2.Instance->CCR1 = 205; htim2.Instance->CCR3 = 135; HAL_Delay(40); htim2.Instance->CCR4 = 200; htim2.Instance->CCR2 = 140; htim2.Instance->CCR1 = 210; htim2.Instance->CCR3 = 140; HAL_Delay(100); htim3.Instance->CCR2 = 210; htim3.Instance->CCR4 = 90; htim3.Instance->CCR1 = 100; htim3.Instance->CCR3 = 208; HAL_Delay(40); htim3.Instance->CCR2 = 200; htim3.Instance->CCR4 = 100; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 197; HAL_Delay(40); htim3.Instance->CCR2 = 195; htim3.Instance->CCR4 = 105; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 190; htim3.Instance->CCR4 = 110; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR2 = 185; htim3.Instance->CCR4 = 115; htim3.Instance->CCR1 = 125; htim3.Instance->CCR3 = 180; HAL_Delay(100); //Body turn htim2.Instance->CCR1 = 205; htim2.Instance->CCR4 = 197; htim2.Instance->CCR2 = 135; htim2.Instance->CCR3 = 135; HAL_Delay(40); htim2.Instance->CCR1 = 200; htim2.Instance->CCR4 = 194; htim2.Instance->CCR2 = 130; htim2.Instance->CCR3 = 130; HAL_Delay(40); htim2.Instance->CCR1 = 195; htim2.Instance->CCR4 = 190; htim2.Instance->CCR2 = 125; htim2.Instance->CCR3 = 125; HAL_Delay(40); htim2.Instance->CCR1 = 190; htim2.Instance->CCR4 = 185; htim2.Instance->CCR2 = 120; htim2.Instance->CCR3 = 120; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 115; HAL_Delay(100); htim3.Instance->CCR4 = 110; htim3.Instance->CCR2 = 190; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR4 = 105; htim3.Instance->CCR2 = 195; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR4 = 100; htim3.Instance->CCR2 = 200; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR4 = 95; htim3.Instance->CCR2 = 205; htim3.Instance->CCR1 = 105; htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR4 = 85; htim3.Instance->CCR2 = 220; htim3.Instance->CCR1 = 90; htim3.Instance->CCR3 = 215; HAL_Delay(100); htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR1 = 185; htim2.Instance->CCR3 = 115; HAL_Delay(40); htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR1 = 190; htim2.Instance->CCR3 = 120; HAL_Delay(40); htim2.Instance->CCR4 = 185; htim2.Instance->CCR2 = 120; htim2.Instance->CCR1 = 195; htim2.Instance->CCR3 = 125; HAL_Delay(40); htim2.Instance->CCR4 = 190; htim2.Instance->CCR2 = 127; htim2.Instance->CCR1 = 200; htim2.Instance->CCR3 = 130; HAL_Delay(40); htim2.Instance->CCR4 = 195; htim2.Instance->CCR2 = 132; htim2.Instance->CCR1 = 205; htim2.Instance->CCR3 = 135; HAL_Delay(40); htim2.Instance->CCR4 = 200; htim2.Instance->CCR2 = 140; htim2.Instance->CCR1 = 210; htim2.Instance->CCR3 = 140; HAL_Delay(100); htim3.Instance->CCR2 = 210; htim3.Instance->CCR4 = 90; htim3.Instance->CCR1 = 100; htim3.Instance->CCR3 = 208; HAL_Delay(40); htim3.Instance->CCR2 = 200; htim3.Instance->CCR4 = 100; htim3.Instance->CCR1 = 110; htim3.Instance->CCR3 = 197; HAL_Delay(40); htim3.Instance->CCR2 = 195; htim3.Instance->CCR4 = 105; htim3.Instance->CCR1 = 115; htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 190; htim3.Instance->CCR4 = 110; htim3.Instance->CCR1 = 120; htim3.Instance->CCR3 = 185; HAL_Delay(40); htim3.Instance->CCR2 = 185; htim3.Instance->CCR4 = 115; htim3.Instance->CCR1 = 125; htim3.Instance->CCR3 = 180; HAL_Delay(100); //Body turn htim2.Instance->CCR1 = 205; htim2.Instance->CCR4 = 197; htim2.Instance->CCR2 = 135; htim2.Instance->CCR3 = 135; HAL_Delay(40); htim2.Instance->CCR1 = 200; htim2.Instance->CCR4 = 194; htim2.Instance->CCR2 = 130; htim2.Instance->CCR3 = 130; HAL_Delay(40); htim2.Instance->CCR1 = 195; htim2.Instance->CCR4 = 190; htim2.Instance->CCR2 = 125; htim2.Instance->CCR3 = 125; HAL_Delay(40); htim2.Instance->CCR1 = 190; htim2.Instance->CCR4 = 185; htim2.Instance->CCR2 = 120; htim2.Instance->CCR3 = 120; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 115; HAL_Delay(100); } //Turn right if(strncmp(rxMessage,"r",1)==0){ //2. Leg htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 210; HAL_Delay(100); htim2.Instance->CCR2 = 110; HAL_Delay(40); htim2.Instance->CCR2 = 125; HAL_Delay(40); htim2.Instance->CCR2 = 140; HAL_Delay(40); htim2.Instance->CCR2 = 153; HAL_Delay(40); htim2.Instance->CCR2 = 166; HAL_Delay(100); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 185; HAL_Delay(100); //4. Leg htim3.Instance->CCR4 = 110; HAL_Delay(40); htim3.Instance->CCR4 = 105; HAL_Delay(40); htim3.Instance->CCR4 = 100; HAL_Delay(40); htim3.Instance->CCR4 = 95; HAL_Delay(100); htim2.Instance->CCR4 = 175; HAL_Delay(40); htim2.Instance->CCR4 = 170; HAL_Delay(40); htim2.Instance->CCR4 = 165; HAL_Delay(40); htim2.Instance->CCR4 = 160; HAL_Delay(40); htim2.Instance->CCR4 = 155; HAL_Delay(40); htim2.Instance->CCR4 = 150; HAL_Delay(100); htim3.Instance->CCR4 = 100; HAL_Delay(40); htim3.Instance->CCR4 = 105; HAL_Delay(40); htim3.Instance->CCR4 = 110; HAL_Delay(40); htim3.Instance->CCR4 = 115; HAL_Delay(100); //2. Leg htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 210; HAL_Delay(100); htim2.Instance->CCR2 = 160; HAL_Delay(40); htim2.Instance->CCR2 = 150; HAL_Delay(40); htim2.Instance->CCR2 = 140; HAL_Delay(40); htim2.Instance->CCR2 = 130; HAL_Delay(40); htim2.Instance->CCR2 = 120; HAL_Delay(40); htim2.Instance->CCR2 = 110; HAL_Delay(40); htim2.Instance->CCR2 = 100; HAL_Delay(40); htim2.Instance->CCR2 = 90; HAL_Delay(100); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 185; HAL_Delay(100); // 1.leg htim3.Instance->CCR1 = 120; HAL_Delay(40); htim3.Instance->CCR1 = 115; HAL_Delay(40); htim3.Instance->CCR1 = 110; HAL_Delay(40); htim3.Instance->CCR1 = 105; HAL_Delay(40); htim3.Instance->CCR1 = 100; HAL_Delay(100); htim2.Instance->CCR1 = 180; HAL_Delay(40); htim2.Instance->CCR1 = 175; HAL_Delay(40); htim2.Instance->CCR1 = 170; HAL_Delay(40); htim2.Instance->CCR1 = 165; HAL_Delay(40); htim2.Instance->CCR1 = 160; HAL_Delay(40); htim2.Instance->CCR1 = 155; HAL_Delay(40); htim2.Instance->CCR1 = 150; HAL_Delay(40); htim2.Instance->CCR1 = 145; HAL_Delay(40); htim2.Instance->CCR1 = 140; HAL_Delay(40); htim2.Instance->CCR1 = 135; HAL_Delay(40); htim2.Instance->CCR1 = 130; HAL_Delay(100); htim3.Instance->CCR1 = 105; HAL_Delay(40); htim3.Instance->CCR1 = 110; HAL_Delay(40); htim3.Instance->CCR1 = 115; HAL_Delay(40); htim3.Instance->CCR1 = 120; HAL_Delay(40); htim3.Instance->CCR1 = 125; HAL_Delay(100); // 3.leg htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR3 = 205; HAL_Delay(100); htim2.Instance->CCR3 = 105; HAL_Delay(40); htim2.Instance->CCR3 = 100; HAL_Delay(40); htim2.Instance->CCR3 = 95; HAL_Delay(40); htim2.Instance->CCR3 = 90; HAL_Delay(40); htim2.Instance->CCR3 = 85; HAL_Delay(40); htim2.Instance->CCR3 = 80; HAL_Delay(100); htim3.Instance->CCR3 = 205; HAL_Delay(40); htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR3 = 185; HAL_Delay(100); //Body turn htim2.Instance->CCR1 = 140; htim2.Instance->CCR4 = 155; htim2.Instance->CCR2 = 93; htim2.Instance->CCR3 = 85; HAL_Delay(40); htim2.Instance->CCR1 = 150; htim2.Instance->CCR4 = 160; htim2.Instance->CCR2 = 95; htim2.Instance->CCR3 = 90; HAL_Delay(40); htim2.Instance->CCR1 = 160; htim2.Instance->CCR4 = 165; htim2.Instance->CCR2 = 100; htim2.Instance->CCR3 = 95; HAL_Delay(40); htim2.Instance->CCR1 = 170; htim2.Instance->CCR4 = 170; htim2.Instance->CCR2 = 105; htim2.Instance->CCR3 = 100; HAL_Delay(40); htim2.Instance->CCR1 = 180; htim2.Instance->CCR4 = 175; htim2.Instance->CCR2 = 110; htim2.Instance->CCR3 = 105; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; HAL_Delay(100); } //Turn left if(strncmp(rxMessage,"l",1)==0){ //2. Leg htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 210; HAL_Delay(100); htim2.Instance->CCR2 = 110; HAL_Delay(40); htim2.Instance->CCR2 = 125; HAL_Delay(40); htim2.Instance->CCR2 = 140; HAL_Delay(40); htim2.Instance->CCR2 = 153; HAL_Delay(40); htim2.Instance->CCR2 = 166; HAL_Delay(100); htim3.Instance->CCR2 = 205; HAL_Delay(40); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 185; HAL_Delay(100); //4. Leg htim3.Instance->CCR4 = 110; HAL_Delay(40); htim3.Instance->CCR4 = 105; HAL_Delay(40); htim3.Instance->CCR4 = 100; HAL_Delay(40); htim3.Instance->CCR4 = 95; HAL_Delay(100); htim2.Instance->CCR4 = 185; HAL_Delay(40); htim2.Instance->CCR4 = 193; HAL_Delay(40); htim2.Instance->CCR4 = 200; HAL_Delay(40); htim2.Instance->CCR4 = 207; HAL_Delay(40); htim2.Instance->CCR4 = 213; HAL_Delay(40); htim2.Instance->CCR4 = 220; HAL_Delay(100); htim3.Instance->CCR4 = 100; HAL_Delay(40); htim3.Instance->CCR4 = 105; HAL_Delay(40); htim3.Instance->CCR4 = 110; HAL_Delay(40); htim3.Instance->CCR4 = 115; HAL_Delay(100); // 3.leg htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR3 = 205; HAL_Delay(100); htim2.Instance->CCR3 = 115; HAL_Delay(40); htim2.Instance->CCR3 = 125; HAL_Delay(40); htim2.Instance->CCR3 = 138; HAL_Delay(40); htim2.Instance->CCR3 = 150; HAL_Delay(40); htim2.Instance->CCR3 = 163; HAL_Delay(40); htim2.Instance->CCR3 = 177; HAL_Delay(100); htim3.Instance->CCR3 = 205; HAL_Delay(40); htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR3 = 185; HAL_Delay(100); // 1.leg htim3.Instance->CCR1 = 120; HAL_Delay(40); htim3.Instance->CCR1 = 115; HAL_Delay(40); htim3.Instance->CCR1 = 110; HAL_Delay(40); htim3.Instance->CCR1 = 105; HAL_Delay(40); htim3.Instance->CCR1 = 100; HAL_Delay(100); htim2.Instance->CCR1 = 190; HAL_Delay(40); htim2.Instance->CCR1 = 195; HAL_Delay(40); htim2.Instance->CCR1 = 200; HAL_Delay(40); htim2.Instance->CCR1 = 205; HAL_Delay(40); htim2.Instance->CCR1 = 210; HAL_Delay(40); htim2.Instance->CCR1 = 215; HAL_Delay(40); htim2.Instance->CCR1 = 220; HAL_Delay(100); htim3.Instance->CCR1 = 105; HAL_Delay(40); htim3.Instance->CCR1 = 110; HAL_Delay(40); htim3.Instance->CCR1 = 115; HAL_Delay(40); htim3.Instance->CCR1 = 120; HAL_Delay(40); htim3.Instance->CCR1 = 125; HAL_Delay(100); //Body turn htim2.Instance->CCR1 = 215; htim2.Instance->CCR4 = 215; htim2.Instance->CCR2 = 160; htim2.Instance->CCR3 = 170; HAL_Delay(40); htim2.Instance->CCR1 = 210; htim2.Instance->CCR4 = 210; htim2.Instance->CCR2 = 150; htim2.Instance->CCR3 = 160; HAL_Delay(40); htim2.Instance->CCR1 = 205; htim2.Instance->CCR4 = 205; htim2.Instance->CCR2 = 140; htim2.Instance->CCR3 = 150; HAL_Delay(40); htim2.Instance->CCR1 = 200; htim2.Instance->CCR4 = 197; htim2.Instance->CCR2 = 130; htim2.Instance->CCR3 = 140; HAL_Delay(40); htim2.Instance->CCR1 = 195; htim2.Instance->CCR4 = 190; htim2.Instance->CCR2 = 125; htim2.Instance->CCR3 = 130; HAL_Delay(40); htim2.Instance->CCR1 = 190; htim2.Instance->CCR4 = 185; htim2.Instance->CCR2 = 120; htim2.Instance->CCR3 = 120; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR4 = 180; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; HAL_Delay(100); } if(strncmp(rxMessage,"n",1)==0){ htim2.Instance->CCR1 = 185; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; htim2.Instance->CCR4 = 180; htim3.Instance->CCR1 = 125; htim3.Instance->CCR2 = 185; htim3.Instance->CCR3 = 180; htim3.Instance->CCR4 = 115; htim4.Instance->CCR1 = 125; htim4.Instance->CCR2 = 180; htim4.Instance->CCR3 = 190; htim4.Instance->CCR4 = 125; } //forward should come after Start(n) if(strncmp(rxMessage,"i",1)==0){ //Left-Front leg htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 205; HAL_Delay(100); htim2.Instance->CCR2 = 113; htim4.Instance->CCR2 = 176; HAL_Delay(40); htim2.Instance->CCR2 = 110; htim4.Instance->CCR2 = 170; HAL_Delay(40); htim2.Instance->CCR2 = 105; htim4.Instance->CCR2 = 165; HAL_Delay(40); htim2.Instance->CCR2 = 100; htim4.Instance->CCR2 = 160; HAL_Delay(40); htim2.Instance->CCR2 = 93; htim4.Instance->CCR2 = 155; HAL_Delay(40); htim2.Instance->CCR2 = 85; htim4.Instance->CCR2 = 150; HAL_Delay(100); htim3.Instance->CCR2 = 200; HAL_Delay(40); htim3.Instance->CCR2 = 195; HAL_Delay(40); htim3.Instance->CCR2 = 190; HAL_Delay(40); htim3.Instance->CCR2 = 185; HAL_Delay(40); htim3.Instance->CCR2 = 178; HAL_Delay(100); /////////////////////////////////////////////////// Move forward 1 htim2.Instance->CCR1 = 180; htim2.Instance->CCR3 = 107; htim2.Instance->CCR4 = 184; htim4.Instance->CCR2 = 153; htim4.Instance->CCR3 = 185; htim4.Instance->CCR4 = 128; htim3.Instance->CCR4 = 118; htim2.Instance->CCR2 = 87; htim4.Instance->CCR1 = 122; HAL_Delay(40); htim2.Instance->CCR1 = 178; htim2.Instance->CCR3 = 106; htim2.Instance->CCR4 = 188; htim4.Instance->CCR2 = 156; htim4.Instance->CCR3 = 182; htim4.Instance->CCR4 = 130; htim3.Instance->CCR4 = 120; htim2.Instance->CCR2 = 88; htim4.Instance->CCR1 = 119; HAL_Delay(40); htim2.Instance->CCR1 = 175; htim2.Instance->CCR3 = 104; htim2.Instance->CCR4 = 192; htim4.Instance->CCR2 = 159; htim4.Instance->CCR3 = 179; htim4.Instance->CCR4 = 132; htim3.Instance->CCR4 = 123; htim2.Instance->CCR2 = 89; HAL_Delay(40); htim2.Instance->CCR1 = 172; htim2.Instance->CCR3 = 101; htim2.Instance->CCR4 = 196; htim4.Instance->CCR2 = 162; htim4.Instance->CCR3 = 175; htim4.Instance->CCR4 = 134; htim3.Instance->CCR3 = 178; htim2.Instance->CCR2 = 90; HAL_Delay(40); htim2.Instance->CCR1 = 168; htim2.Instance->CCR3 = 98; htim2.Instance->CCR4 = 198; htim4.Instance->CCR2 = 166; htim4.Instance->CCR3 = 171; htim4.Instance->CCR4 = 136; htim3.Instance->CCR3 = 177; htim2.Instance->CCR2 = 91; HAL_Delay(40); htim2.Instance->CCR1 = 164; htim2.Instance->CCR3 = 96; htim2.Instance->CCR4 = 199; htim4.Instance->CCR2 = 170; htim4.Instance->CCR3 = 170; htim4.Instance->CCR4 = 140; htim3.Instance->CCR3 = 176; htim2.Instance->CCR2 = 92; HAL_Delay(40); htim2.Instance->CCR1 = 160; htim2.Instance->CCR3 = 93; htim2.Instance->CCR4 = 200; htim4.Instance->CCR2 = 174; htim4.Instance->CCR3 = 168; htim4.Instance->CCR4 = 143; htim3.Instance->CCR3 = 175; htim2.Instance->CCR2 = 93; HAL_Delay(100); //////////////////////////////////////////////////// //Right Rear Leg htim3.Instance->CCR3 = 180; HAL_Delay(40); htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR3 = 205; HAL_Delay(100); htim2.Instance->CCR3 = 97; htim4.Instance->CCR3 = 172; HAL_Delay(40); htim2.Instance->CCR3 = 101; htim4.Instance->CCR3 = 176; HAL_Delay(40); htim2.Instance->CCR3 = 106; htim4.Instance->CCR3 = 184; HAL_Delay(40); htim2.Instance->CCR3 = 114; htim4.Instance->CCR3 = 190; HAL_Delay(40); htim2.Instance->CCR3 = 130; htim4.Instance->CCR3 = 197; HAL_Delay(40); htim2.Instance->CCR3 = 137; HAL_Delay(100); htim3.Instance->CCR3 = 210; HAL_Delay(40); htim3.Instance->CCR3 = 205; HAL_Delay(40); htim3.Instance->CCR3 = 200; HAL_Delay(40); htim3.Instance->CCR3 = 195; HAL_Delay(40); htim3.Instance->CCR3 = 190; HAL_Delay(40); htim3.Instance->CCR3 = 180; HAL_Delay(100); //Right Front leg htim3.Instance->CCR1 = 118; HAL_Delay(40); htim3.Instance->CCR1 = 112; HAL_Delay(40); htim3.Instance->CCR1 = 105; HAL_Delay(40); htim3.Instance->CCR1 = 100; HAL_Delay(40); htim3.Instance->CCR1 = 95; HAL_Delay(100); htim2.Instance->CCR1 = 166; HAL_Delay(40); htim2.Instance->CCR1 = 175; HAL_Delay(40); htim2.Instance->CCR1 = 183; htim4.Instance->CCR1 = 127; HAL_Delay(40); htim2.Instance->CCR1 = 190; htim4.Instance->CCR1 = 132; HAL_Delay(40); htim2.Instance->CCR1 = 197; htim4.Instance->CCR1 = 136; HAL_Delay(40); htim2.Instance->CCR1 = 205; htim4.Instance->CCR1 = 140; HAL_Delay(40); htim2.Instance->CCR1 = 207; HAL_Delay(100); htim3.Instance->CCR1 = 100; HAL_Delay(40); htim3.Instance->CCR1 = 107; HAL_Delay(40); htim3.Instance->CCR1 = 114; HAL_Delay(40); htim3.Instance->CCR1 = 120; HAL_Delay(40); htim3.Instance->CCR1 = 125; HAL_Delay(100); // /////////////////////////////////////////////////// Move forward 2 htim2.Instance->CCR1 = 206; htim2.Instance->CCR2 = 94; htim2.Instance->CCR3 = 135; htim2.Instance->CCR4 = 202; htim3.Instance->CCR4 = 124; htim4.Instance->CCR1 = 138; htim4.Instance->CCR4 = 145; htim4.Instance->CCR2 = 175; htim4.Instance->CCR3 = 196; HAL_Delay(40); htim2.Instance->CCR1 = 205; htim2.Instance->CCR2 = 98; htim2.Instance->CCR3 = 130; htim2.Instance->CCR4 = 204; htim3.Instance->CCR4 = 125; htim4.Instance->CCR1 = 135; htim4.Instance->CCR4 = 147; htim4.Instance->CCR2 = 177; htim4.Instance->CCR3 = 195; HAL_Delay(40); htim2.Instance->CCR1 = 203; htim2.Instance->CCR2 = 103; htim2.Instance->CCR3 = 126; htim2.Instance->CCR4 = 207; htim3.Instance->CCR4 = 126; htim4.Instance->CCR1 = 133; htim4.Instance->CCR4 = 149; htim4.Instance->CCR2 = 179; htim4.Instance->CCR3 = 194; HAL_Delay(40); htim2.Instance->CCR1 = 201; htim2.Instance->CCR2 = 108; htim2.Instance->CCR3 = 122; htim2.Instance->CCR4 = 209; htim3.Instance->CCR4 = 127; htim4.Instance->CCR1 = 130; htim4.Instance->CCR4 = 153; htim4.Instance->CCR2 = 180; htim4.Instance->CCR3 = 193; HAL_Delay(40); htim2.Instance->CCR1 = 197; htim2.Instance->CCR2 = 111; htim2.Instance->CCR3 = 116; htim2.Instance->CCR4 = 210; htim3.Instance->CCR4 = 128; htim4.Instance->CCR1 = 128; htim4.Instance->CCR4 = 159; htim4.Instance->CCR2 = 181; htim4.Instance->CCR3 = 192; HAL_Delay(40); htim2.Instance->CCR1 = 192; htim2.Instance->CCR2 = 114; htim2.Instance->CCR3 = 113; htim2.Instance->CCR4 = 211; htim3.Instance->CCR4 = 130; htim4.Instance->CCR1 = 126; htim4.Instance->CCR4 = 165; htim4.Instance->CCR2 = 182; htim4.Instance->CCR3 = 190; HAL_Delay(40); htim2.Instance->CCR1 = 185; htim2.Instance->CCR2 = 117; htim2.Instance->CCR3 = 110; htim2.Instance->CCR4 = 212; htim3.Instance->CCR4 = 132; htim4.Instance->CCR1 = 125; htim4.Instance->CCR4 = 172; HAL_Delay(100); //////////////////////////////////////////////////// //Left Rear leg htim3.Instance->CCR4 = 130; HAL_Delay(40); htim3.Instance->CCR4 = 125; HAL_Delay(40); htim3.Instance->CCR4 = 119; HAL_Delay(40); htim3.Instance->CCR4 = 115; HAL_Delay(100); htim2.Instance->CCR4 = 210; htim4.Instance->CCR4 = 170; HAL_Delay(40); htim2.Instance->CCR4 = 206; htim4.Instance->CCR4 = 160; HAL_Delay(40); htim2.Instance->CCR4 = 197; htim4.Instance->CCR4 = 150; HAL_Delay(40); htim2.Instance->CCR4 = 190; htim4.Instance->CCR4 = 140; HAL_Delay(40); htim2.Instance->CCR4 = 185; htim4.Instance->CCR4 = 130; HAL_Delay(40); htim2.Instance->CCR4 = 180; htim4.Instance->CCR4 = 125; HAL_Delay(100); } } //} /* 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 CPU, AHB and APB busses clocks */ 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; RCC_OscInitStruct.PLL.PLLM = 8; 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 busses 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(); } } /** * @brief ADC1 Initialization Function * @param None * @retval None */ static void MX_ADC1_Init(void) { /* USER CODE BEGIN ADC1_Init 0 */ /* USER CODE END ADC1_Init 0 */ ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC1_Init 1 */ /* USER CODE END ADC1_Init 1 */ /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = DISABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_11; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN ADC1_Init 2 */ /* USER CODE END ADC1_Init 2 */ } /** * @brief TIM2 Initialization Function * @param None * @retval None */ static void MX_TIM2_Init(void) { /* USER CODE BEGIN TIM2_Init 0 */ /* USER CODE END TIM2_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; /* USER CODE BEGIN TIM2_Init 1 */ /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; htim2.Init.Prescaler = 900-1; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 1000-1; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM2_Init 2 */ /* USER CODE END TIM2_Init 2 */ HAL_TIM_MspPostInit(&htim2); } /** * @brief TIM3 Initialization Function * @param None * @retval None */ static void MX_TIM3_Init(void) { /* USER CODE BEGIN TIM3_Init 0 */ /* USER CODE END TIM3_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; /* USER CODE BEGIN TIM3_Init 1 */ /* USER CODE END TIM3_Init 1 */ htim3.Instance = TIM3; htim3.Init.Prescaler = 900-1; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 1000-1; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim3) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_Init(&htim3) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM3_Init 2 */ /* USER CODE END TIM3_Init 2 */ HAL_TIM_MspPostInit(&htim3); } /** * @brief TIM4 Initialization Function * @param None * @retval None */ static void MX_TIM4_Init(void) { /* USER CODE BEGIN TIM4_Init 0 */ /* USER CODE END TIM4_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; /* USER CODE BEGIN TIM4_Init 1 */ /* USER CODE END TIM4_Init 1 */ htim4.Instance = TIM4; htim4.Init.Prescaler = 900-1; htim4.Init.CounterMode = TIM_COUNTERMODE_UP; htim4.Init.Period = 1000-1; htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim4) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_Init(&htim4) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM4_Init 2 */ /* USER CODE END TIM4_Init 2 */ HAL_TIM_MspPostInit(&htim4); } /** * @brief USART1 Initialization Function * @param None * @retval None */ static void MX_USART1_UART_Init(void) { /* USER CODE BEGIN USART1_Init 0 */ /* USER CODE END USART1_Init 0 */ /* USER CODE BEGIN USART1_Init 1 */ /* USER CODE END USART1_Init 1 */ huart1.Instance = USART1; huart1.Init.BaudRate = 9600; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin : interrupt_Pin */ GPIO_InitStruct.Pin = interrupt_Pin; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(interrupt_GPIO_Port, &GPIO_InitStruct); /* EXTI interrupt init*/ HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); } /* USER CODE BEGIN 4 */ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { /* Prevent unused argument(s) compilation warning */ UNUSED(GPIO_Pin); /* NOTE: This function Should not be modified, when the callback is needed, the HAL_GPIO_EXTI_Callback could be implemented in the user file */ htim2.Instance->CCR1 = 185; htim2.Instance->CCR2 = 115; htim2.Instance->CCR3 = 110; htim2.Instance->CCR4 = 180; htim3.Instance->CCR1 = 125; htim3.Instance->CCR2 = 185; htim3.Instance->CCR3 = 180; htim3.Instance->CCR4 = 115; htim4.Instance->CCR1 = 125; htim4.Instance->CCR2 = 180; htim4.Instance->CCR3 = 190; htim4.Instance->CCR4 = 125; HAL_Delay(100); } /* 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 */ /* 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, tex: 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****/