The plank's activity is a side-to-side swing (not back-and-forth as with a playground swing). Below is a simplified diagram (A and B are the Fans and the + is placement of the 10-DOF on the plank) :
|.......................................|
|.......................................|
|.......................................|
|.......................................|
|.......................................|
========+========
<FanA................ FanB>
If plank is at standstill: Fan A at max, pushing the plank to the right. Fan B idle.
If plank is moving right (towards B): Fan A at max until a change of direction. Fan B idle.
If plank is moving left (towards A): Fan B at max until a change of direction. Fan A idle.
A version of this experiment has worked in the past by my setting the fan increments (delay) manually based on the length of the hang. I need a more responsive solution.
I have been playing with the 10-DOF and figured I'd use the x-axis readings to detect the direction and activate the fans accordingly. If it was moving along the x-axis to the right, I was receiving a positive reading, if it switched direction, the reading would drop below 0, heading the other direction. Here's the loop code:
Code: Select all
void loop() {
/* Get a new sensor event */
sensors_event_t event;
/* Retrieve data (acceleration is measured in m/s^2) */
accel.getEvent(&event);
float markerX = event.acceleration.x;
if(markerX < 0){
analogWrite(ledPin1, 255);
analogWrite(ledPin2, 0);
}
else{
analogWrite(ledPin2, 255);
analogWrite(ledPin1, 0);
}
}
Thank you in advance!