Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 6:12ff056ab2c1, committed 2022-01-19
- Comitter:
- saloutos
- Date:
- Wed Jan 19 19:32:40 2022 +0000
- Parent:
- 5:e4e96d1b446f
- Commit message:
- added rezeroing of the ATI sensor ;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Nov 18 20:34:22 2021 +0000
+++ b/main.cpp Wed Jan 19 19:32:40 2022 +0000
@@ -28,7 +28,7 @@
/*---------------------- Ethernet setup ----------------------*/
const int SERVER_PORT = 11223;
-const char* SERVER_ADDRESS = "192.168.1.2"; // Adress of the other Mbed (Mbed B)
+const char* SERVER_ADDRESS = "192.168.1.200"; // Adress of the other Mbed (Mbed B)
const int LOCAL_PORT = 11223;
const char* ip = "192.168.1.1"; // Mbed A = 1; Mbed B = 2
const char* mask = "255.255.255.0";
@@ -47,7 +47,8 @@
/*---------------------- IMU setup ----------------------*/
-// TODO: add this eventually
+// TODO: add this so that we can collect hand-held data
+
/*---------------------- LTC chip setup ----------------------*/
@@ -73,7 +74,7 @@
ltc_spi adc_data;
int16_t ati_data[6];
float ati_filt[6];
-float FILT_COEF = 0.10f;
+float FILT_COEF = 1.0f; //0.10f;
// calibration matrix for ATI sensor
float Fxc[6] = {-0.1971322934773, -0.04349257334311, 2.298051028435, -80.35044049387, 1.362983909976, 78.23673392118};
@@ -527,7 +528,7 @@
wait_ms(1);
}
pc.printf("ATI sensor is calibrated with biases of: %.2f, %.2f, %.2f, %.2f, %.2f, %.2f \n\r", bias[0],bias[1],bias[2],bias[3],bias[4],bias[5]);
-
+
// TODO: Add calibration for force sensor? Only necessary if the force sensor neural network is being evaluated online
//calibrateSensor(offsets);
@@ -540,7 +541,7 @@
while (true) {
- if(LTC_ticker_activated == true) {
+ /*if(LTC_ticker_activated == true) {
// Clear flag
LTC_ticker_activated = false;
// Sample from LTC chip, filter data
@@ -573,11 +574,44 @@
// pc.printf("%d,%d,%d,%d,%d,%d,%d,%d\n\r", pr_data[0],pr_data[1],pr_data[2],pr_data[3],pr_data[4],pr_data[5],pr_data[6],pr_data[7]);
// Pack and send the ethernet message
+ //sprintf(send_buf, "%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,%d\n", msg_timer.read(),ft_data[0],ft_data[1],ft_data[2], pr_data[0],pr_data[1],pr_data[2],pr_data[3],pr_data[4],pr_data[5],pr_data[6],pr_data[7]);
+// sprintf(send_buf, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", ati_data[0],ati_data[1],ati_data[2],ati_data[3],ati_data[4],ati_data[5], pr_data[0],pr_data[1],pr_data[2],pr_data[3],pr_data[4],pr_data[5],pr_data[6],pr_data[7]);
+ //server.sendto(client, send_buf, sizeof(send_buf)); // send message, look for '\n' character when decoding the string
+
+ }*/
+
+ // Receive a message from server (Mbed B)
+ char buf[256];
+ int n = server.recvfrom(&client, buf, 256); // could also use server.recv(buf, 256)?
+ buf[n] = '\0';
+ //pc.printf("Received message back from server: '%s'\n\r", buf);
+
+ if (buf[0]=='z') { // re-zero ATI sensor
+ for(int i=0; i<100; i++){ // read 100 times and take average
+ read_LTC_data();
+ for(int j=0; j<6; j++){
+ bias[j] += 0.01*(float)ati_data[j];
+ }
+ wait_ms(1);
+ }
+ }
+
+ if (buf[0]=='r') {
+ read_LTC_data();
+ filter_LTC_data();
+ convert_LTC_data();
+ read_bmp_data();
+ pr_data[0] = int(sn_data1.pressure)-100000; // pressure is returned in Pa, could subtract actual sea level pressure here
+ pr_data[1] = int(sn_data2.pressure)-100000;
+ pr_data[2] = int(sn_data3.pressure)-100000;
+ pr_data[3] = int(sn_data4.pressure)-100000;
+ pr_data[4] = int(sn_data5.pressure)-100000;
+ pr_data[5] = int(sn_data6.pressure)-100000;
+ pr_data[6] = int(sn_data7.pressure)-100000;
+ pr_data[7] = int(sn_data8.pressure)-100000;
sprintf(send_buf, "%f,%f,%f,%f,%d,%d,%d,%d,%d,%d,%d,%d\n", msg_timer.read(),ft_data[0],ft_data[1],ft_data[2], pr_data[0],pr_data[1],pr_data[2],pr_data[3],pr_data[4],pr_data[5],pr_data[6],pr_data[7]);
-// sprintf(send_buf, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", ati_data[0],ati_data[1],ati_data[2],ati_data[3],ati_data[4],ati_data[5], pr_data[0],pr_data[1],pr_data[2],pr_data[3],pr_data[4],pr_data[5],pr_data[6],pr_data[7]);
server.sendto(client, send_buf, sizeof(send_buf)); // send message, look for '\n' character when decoding the string
-
- }
+ }
}
