Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Commit

Permalink
Updated uncompleted example
Browse files Browse the repository at this point in the history
  • Loading branch information
jaenrig-ifx committed Mar 5, 2020
1 parent de20131 commit f1c4801
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions examples/DrillTrigger_SpeedAsNumber/DrillTrigger_SpeedAsNumber.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,41 @@
* For basic setup just create a Tle493d() object. If you want to use the wake up mode please use Tle493d_w2b6(). Also
* the setUpdateRate() method is slightly different for different variants
*/


#include <Tle493d.h>

Tle493d Tle493dMagnetic3DSensor = Tle493d();

double X_min=0;
double X_max=0;
double Y_min=0;
double Y_max=0;
double Z_min=0;
double Z_max=0;

void setup() {
Serial.begin(9600);
while (!Serial);
Tle493dMagnetic3DSensor.begin();
Tle493dMagnetic3DSensor.enableTemp();

}

void loop() {
double X_min=0;
double X_max=0;
double Z_min=0;
double Z_max=0;
Tle493dMagnetic3DSensor.updateData();
int spe =0;
double gain_default=1250;
double z = Tle493dMagnetic3DSensor.getZ();
double x = Tle493dMagnetic3DSensor.getX(); /* *zSign */
double y = Tle493dMagnetic3DSensor.getY();
Serial.println("_________________________________");
Serial.println(" ");
int zSign = z < 0 ? -1 : 1;
z = z * zSign;

double x = Tle493dMagnetic3DSensor.getX(); /* *zSign */
//cal for gain. check for new x extrema
if (x<X_min) {
X_min=x;
}
if (x>X_max) {
X_max=x;
}
// ----

double y = Tle493dMagnetic3DSensor.getY(); /* *zSign */
//calibration for gain. check for new y extrema
if (y<Y_min) {
Y_min=y;
}
if (y>Y_max) {
Y_max=y;
}


double sp = -1;
int sp_int=-1;
int number_char=-1;
int counter=0;
int gain = 1;

Serial.print("zsign = ");
Serial.print(zSign);
Expand All @@ -64,16 +46,13 @@ void loop() {
Serial.print(y);
Serial.print(") ; z=");
Serial.println(z);
sp=(atan2(x*zSign,z)+1)*gain;
sp=(atan2(x*zSign,z)+1)*gain_default;
if (sp<0) sp=0;
if (sp>2500) sp=2500;
sp_int=2501-sp;
Serial.print("Speed= ");
Serial.print("Speed= "); //if at no pull at the trigger is bigger than zero some kind of correction or calibration needs to be implemented
Serial.println(sp_int);
number_char=sp_int/50;
Serial.print("Characters for speed = ");
Serial.println(number_char);
delay(500);
delay(1500);


}

0 comments on commit f1c4801

Please sign in to comment.