Hello guys,
Hardware used: Arduino uno, linear actuator, 2 forces sensors, 2 amplifier module (for the sensors), a jetson TX1
What i'm trying to do: Control a stick (a mower stick) within 2 modes:
- power steering mode, the user will press the stick, sensors would recognize the pressure added on the stick and move in the wanted direction
- Autonomous mode, the TX1 will send PWM signal on the arduino, the arduino will copy it and send it back to the linear actuator
What is my problem? Within my program, there is one function where i send the pwm signal to the actuator. In that function, for debugging purpose, I'm sending some data. My program then work, the linear actuator follow the motion of the stick. I'm pushing forward, it goes forward.
But when I comment the Serial.print line, it will go forward but won't stop. And won't go into the loop() any longer.
Here is the function:
void moveServo() {
#ifdef DEBUG
// Serial.println("ca marche avec serial");
#endif
/*
* Function which allow the linear actuator to move by step of 5 us ~ 1°
*/
if (cPos[1] < gPos) {
cPos[0] = cPos[1];
cPos[1] += 5; // modifier tdelay en conséquence
cPos[1] = constrain(cPos[1],1000,2000);
myservo.writeMicroseconds(cPos[1]);// 70 = neutral position
}
if (cPos[1] > gPos){
cPos[0] = cPos[1];
cPos[1] -= 5;
cPos[1] = constrain(cPos[1],1000,2000);
myservo.writeMicroseconds(cPos[1]);
}
//if (cPos == gPos) // nothing
myservo_movetime = millis() + tDelay;
}
And for the whole code: GitHub - Mildred34/Project-06-18
So I'm bit stuck to find from where my problem comes, that's why i'm asking your help. I was thinking about maybe a problem of timer?
I'm using the timer2 for an interruption function to read the data from the sensor each 0,1s. And the timer1 used by the servo library.. And also the timer0 for the millis() function. Every timer in fact.
I'm looking forward hearing from you!