Hi. I'm currently working on a lightsaber and I got the movement detection to work but not the collision. How would I detect the crash?
I'm using an Arduino Nano IoT and I have a gy-521 board.
I looked on google for a long time.
Right now, my code detects if the MPU6050 goes to -1000 after it moves. And it doesn't work. I also tried going to 0.
I attached only the part with the MPU6050.
In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
If the code exceeds the 9000 character inline limit then attach it to a post
SteveMann:
I'm not sure if an accelerometer is the right tool for the job. How would the accelerometer know the sword is simply not moving, versus a hit?
Have you collected accelerometer data sets of when the device is swinging through the air and when the device hits an object?
I would venture to write that once a few data sets are taken, it should be possible that by using a peak detection library to discriminate between regular movement over contact.
SteveMann:
I'm not sure if an accelerometer is the right tool for the job. How would the accelerometer know the sword is simply not moving, versus a hit?
Idahowalker:
Have you collected accelerometer data sets of when the device is swinging through the air and when the device hits an object?
I would venture to write that once a few data sets are taken, it should be possible that by using a peak detection library to discriminate between regular movement over contact.
I suspect contact will mean a bounce, just like switch contacts bouncing.
Paul
step #1 is indeed capturing many samples of lightsaber just moving (no collision) and then with collision.
if you use a fast (ESP32 like) arduino, you might actually try machine learning and use "TensorFlow Lite Micro"
you could also use an Arduino Nano 33 BLE Sense which has the IMU (LSM9DS1) on board and the power to handle machine learning (TinyML) with a 32-bit ARM Cortex-M4 CPU running at 64 MHz (it even has a MP34DT05 based microphone that could provide supplemental data)
J-M-L:
step #1 is indeed capturing many samples of lightsaber just moving (no collision) and then with collision.
if you use a fast (ESP32 like) arduino, you might actually try machine learning and use "TensorFlow Lite Micro"
you could also use an Arduino Nano 33 BLE Sense which has the IMU (LSM9DS1) on board and the power to handle machine learning (TinyML) with a 32-bit ARM Cortex-M4 CPU running at 64 MHz (it even has a MP34DT05 based microphone that could provide supplemental data)
Airbags are generally triggered by negative forces of more than 20 Gs (hitting something hard at more than 25km/h that stops the car).
The best way is to Give it a try - I think it’s going to be difficult to not have false positive with just a spike, you'll have the compare the spike from a hit with the spike from just regular movement (moving back and forth the saber)
J-M-L:
Airbags are generally triggered by negative forces of more than 20 Gs (hitting something hard at more than 25km/h that stops the car).
The best way is to Give it a try - I think it’s going to be difficult to not have false positive with just a spike, you'll have the compare the spike from a hit with the spike from just regular movement (moving back and forth the saber)
I suppose that makes sense. Would that just be an issue of sensitivity? Because with swings it would come to a stop slower that a sudden crash.
nonsensicalman:
I suppose that makes sense. Would that just be an issue of sensitivity? Because with swings it would come to a stop slower that a sudden crash.
the accelerometer does not detect a "stop" per se, when you see no acceleration (besides gravity) it means you are at steady speed (including speed of 0, so no motion)
looking at patterns and spikes (ie sudden change above a given threshold) could give you some hints, but that needs to be tested. I'm just saying I'm unsure it's enough
Say you hold your lightsaber as an extension of your arm and move up and down and assume the sensor is at the tip of the lightsaber. The sensor is moving on an arc of circle ("rotating" around your shoulder)
say you start moving up --> you see acceleration on the vertical axis and one of the horizontal axis
you start moving down --> you'll see a change with negative acceleration
depending on how fast you change direction, you'll see a spike
Now if you have a hit along the way, you'll see a some acceleration on some axis depending how you are being hit but it's difficult to quantify how the hit will be measured compared to just performing movements without a hit
You should be measuring the magnitude of the acceleration, which is independent of direction and always positive. This will be large for a hit or sudden stop. If ax, ay, az are the X, Y and Z components of the acceleration,
float acc_mag = sqrt( ax*ax + ay*ay + az*az);
Also, the sensor will be most responsive if it is in the tip of the light saber, which is usually moving fastest and undergoes the largest acceleration (deceleration) when stopped.
Don't forget the relationship between acceleration and force: acceleration = force/mass, which means that small forces can cause large accelerations for lightweight objects such as a light saber.
Time to build your thingy (or just tape the MPU-6050 AND the Arduino to the end of a wooden stick, no long leads allowed for I2C connections) and show us some measurement results!
Don't worry, the sensor is rated to survive 10000 g crashes.