
test
Revision 14:b3530522908e, committed 2020-12-14
- Comitter:
- ruslanbredun
- Date:
- Mon Dec 14 10:20:16 2020 +0000
- Parent:
- 13:0c732e06d675
- Child:
- 15:0f52feb640cf
- Commit message:
- 11.12.20
Changed in this revision
--- a/AS5045/AS5045.h Sun Dec 06 11:06:23 2020 +0000 +++ b/AS5045/AS5045.h Mon Dec 14 10:20:16 2020 +0000 @@ -19,7 +19,7 @@ static const float MAX_VALUE = 1024; // Maximum possible encoder position value (ticks for full rotation) static const float RESOLUTION = 0.3515625; // Encoder resolution (0.08789 degrees per tick) - static const float SPI_FREQ = 5000; // Frequency of the SPI bus + static const float SPI_FREQ = 500000; // Frequency of the SPI bus }; #endif // AS5045_H
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Watchdog.lib Mon Dec 14 10:20:16 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/3mdeb/code/Watchdog/#76136c6dc64d
--- a/global.h Sun Dec 06 11:06:23 2020 +0000 +++ b/global.h Mon Dec 14 10:20:16 2020 +0000 @@ -7,13 +7,15 @@ #include "E18_D80NK.h" #include <RS485.h> #include "DS1820.h" +#include "Watchdog.h" #define MAX_SENSOSRS 32 #define BLINKING_RATE 500 -#define TEST_REQUEST 0 -#define DEMO_CODE 1 +#define TEST_WATCHDOG 0 +#define TEST_REQUEST 0 +#define MAIN_CODE 1 // rs-485 pins #define UART1_TX PB_6
--- a/main.cpp Sun Dec 06 11:06:23 2020 +0000 +++ b/main.cpp Mon Dec 14 10:20:16 2020 +0000 @@ -1,73 +1,67 @@ #include <global.h> -//RS485 RS485(UART2_TX,UART2_RX,DE_TXD_2); // Tx, Rx , !RE and DE MAX485 pin Serial RS2(UART2_TX, UART2_RX); Serial RS1(UART1_TX, UART1_RX); Timer timer; +Watchdog watchDog; + typedef uint8_t byte; DigitalOut Select1(DE_TXD_1); DigitalOut Select2(DE_TXD_2); - +bool sendFlag = false; +char c = '1'; -bool sendFlag = false; -bool sendFlag1 = false; -int cmd[13] = {0xA5,0x40,0x90,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7D}; -char inChar[52]; -int index = 0; -char c = '1'; -const unsigned char CRC7_POLY = 0x91; +// ----------------------------- For future --------------------------------------- +// Counting CRC for modbus package +//const unsigned char CRC7_POLY = 0x91; -unsigned char getCRC(unsigned char message[], unsigned char length) -{ - unsigned char i, j, crc = 0; - - for (i = 0; i < length; i++) { - crc ^= message[i]; - for (j = 0; j < 8; j++) { - if (crc & 1) - crc ^= CRC7_POLY; - crc >>= 1; - } - } - return crc; - -} +//unsigned char getCRC(unsigned char message[], unsigned char length) +//{ +// unsigned char i, j, crc = 0; +// +// for (i = 0; i < length; i++) { +// crc ^= message[i]; +// for (j = 0; j < 8; j++) { +// if (crc & 1) +// crc ^= CRC7_POLY; +// crc >>= 1; +// } +// } +// return crc; +// +//} void UART2_callback() { c = RS2.getc(); - if(c == '4') { + if(c == '5') { sendFlag = true; } else { Select2 = 1; wait_ms(90); Select2 = 0; } - } int main() { RS2.baud (115200); + RS1.baud (115200); Select1 = 0; Select2 = 0; RS2.attach(&UART2_callback); - //RS1.attach(&UART1_callback); - -#if DEMO_CODE - int US1_data = 0,US2_data = 0, US3_data = 0; - - int Lift_IR1 = 0,Lift_IR2 = 0; +#if MAIN_CODE + int US1_data = 0,US2_data = 0, US3_data = 0, Lift_IR1 = 0,Lift_IR2 = 0, Enc_left_data = 0, Enc_right_data = 0; bool IR1_data = 0,IR2_data = 0; + float temp_one_value = -1, temp_two_value = -1, currentTime = 0, previousTime = 0; + + timer.start(); - float temp_one_value = -1, temp_two_value = -1, Enc_left_data = 0, Enc_right_data = 0, time = 0; - - Timer timer1; - timer1.start(); + watchDog.Configure(5.0); OneWire oneWire(PA_11); // substitute D8 with the actual pin name connected to the 1-wire bus int sensorsFound = 0; @@ -98,51 +92,60 @@ } while (true) { - timer1.reset(); + watchDog.Service(); + + currentTime = timer.read(); + + if((currentTime - previousTime) >= 0.1) { + previousTime = currentTime; + + for (int i = 0; i < sensorsFound; i++) { + ds1820[i]->startConversion(); + wait_ms(1); + } - for (int i = 0; i < sensorsFound; i++) { - ds1820[i]->startConversion(); - wait_ms(1); - //temp_one_value = ds1820[i]->read(); - //temp_two_value = i; + US_sensor_left.startMeasurement (); + US1_data = US_sensor_left.getDistance_cm (); + wait_ms(20); + + US_sensor_middle.startMeasurement (); + US2_data = US_sensor_middle.getDistance_cm (); + wait_ms(20); + + US_sensor_right.startMeasurement (); + US3_data = US_sensor_right.getDistance_cm (); + wait_ms(20); + + IR1_data = IR_sensor_left.checkObstacle (); + IR2_data = IR_sensor_right.checkObstacle (); + + Lift_IR1 = Lift1.read(); + Lift_IR2 = Lift2.read(); + + + if (ds1820[0]->isPresent() ) { + temp_one_value = ds1820[0]->read(); + } + if (ds1820[1]->isPresent() ) { + temp_two_value = ds1820[1]->read(); + } } - US_sensor_left.startMeasurement (); - US1_data = US_sensor_left.getDistance_cm (); - wait_ms(15); - US_sensor_middle.startMeasurement (); - US2_data = US_sensor_middle.getDistance_cm (); - wait_ms(15); - US_sensor_right.startMeasurement (); - US3_data = US_sensor_right.getDistance_cm (); - wait_ms(15); - IR1_data = IR_sensor_left.checkObstacle (); - IR2_data = IR_sensor_right.checkObstacle (); - - - Enc_left_data = Enc_left.getAngle(); - Enc_right_data = Enc_right.getAngle(); + Enc_left_data = Enc_left.getPosition(); + Enc_right_data = Enc_right.getPosition(); + + Select1 = 1; + RS1.printf ("%d_%d\r\n", Enc_left_data, Enc_right_data); + wait_ms(1); + Select1 = 0; - Lift_IR1 = Lift1.read(); - Lift_IR2 = Lift2.read(); - - time = timer1.read(); - - if (ds1820[0]->isPresent() ) { - //pc.printf("temp[%d] = %3.1f%cC\r\n", 0, ds1820[0]->read(), 176); // read temperature - temp_one_value = ds1820[0]->read(); - } - if (ds1820[1]->isPresent() ) { - //pc.printf("temp[%d] = %3.1f%cC\r\n", 1, ds1820[1]->read(), 176); // read temperature - temp_two_value = ds1820[1]->read(); - } - //if(sendFlag) { + if(sendFlag) { Select2 = 1; - RS2.printf ("%d_%d_%d_%d_%d_%d_%d_%3.1f_%3.1f_%3.1f_%3.1f_%f\r\n", US1_data, US2_data, US3_data, IR1_data, IR2_data, Lift_IR1, Lift_IR2, temp_one_value, temp_two_value, Enc_right_data, Enc_left_data, time); //,(int)((Vcc -24 ) * 5 + 50)); + RS2.printf ("%d_%d_%d_%d_%d_%d_%d_%3.1f_%3.1f\r\n", US1_data, US2_data, US3_data, IR1_data, IR2_data, Lift_IR1, Lift_IR2, temp_one_value, temp_two_value); //,(int)((Vcc -24 ) * 5 + 50)); wait_ms(5); sendFlag = false; Select2 = 0; - // } + } } #endif @@ -164,4 +167,5 @@ } #endif + } \ No newline at end of file