Eric_O
Advanced Member level 4
My code here under works :
- Axis X drives servo LOWER (Timer2 and Timer0), portd.bo
- Axis Y drives servo UPPER (Timer2 and Timer1)
But ...
- servo LOWER turns too fast in both directions, left and right while a very short shifting on left or right way with joystick
- servo UPER turns too slowly step after step in both directions, left and right while a very short shifting on up and down way with joystick
Question :
How could I control turns slowly while shifting joystick on the all scale of the displacement of the stick ?
Part of the code :
Thanks for your help !
Merci beaucoup.
Eric
- Axis X drives servo LOWER (Timer2 and Timer0), portd.bo
- Axis Y drives servo UPPER (Timer2 and Timer1)
But ...
- servo LOWER turns too fast in both directions, left and right while a very short shifting on left or right way with joystick
- servo UPER turns too slowly step after step in both directions, left and right while a very short shifting on up and down way with joystick
Question :
How could I control turns slowly while shifting joystick on the all scale of the displacement of the stick ?
Part of the code :
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 while(1) { // Servomotor LOWER 270° : TOWER PRO M996R (270°) Init_Timer2(); Init_Timer0(); p0 = &TMR0; joystick_X = (ADC_read(0)); // Reads Y axis value with channel 0 (AN0) on pin #2. //if ((joystick_X <= 500) && (joystick_X > 0)) if ((joystick_X <= 500) && (joystick_X > 100)) { //consigne_0 = 256 - 226; // consigne_0 = 256 - 226 => 226 à 256 = 30 x 1 uS = 30 uS = 0,03 mS. // ROTATION CONTINUE DROITE. //consigne_0 = 256 - (0.25 * joystick_X); consigne_0 = joystick_X / 4; //consigne_0 = joystick_X / 5; sprintl(*p0, "%3u", consigne_0); Init_Timer2(); Init_Timer0(); while(cnt0 < (consigne_0 / 10)) { portd.b1 = 0; portd.b0 = 1; // Servomotor LOWER ON. portc.b2 = 1; // LED ON. } portd.b0 = 0; portc.b2 = 0; } //if ((joystick_X >= 524) && (joystick_X < 1024)) if ((joystick_X >= 524) && (joystick_X < 924)) { //consigne_0 = 256 - 156; // consigne_0 = 256 - 156 => 156 à 256 = 100 x 1 uS = 100 uS = 0,1 mS. // ROTATION CONTINUE GAUCHE. //consigne_0 = 256 - (0.25 * joystick_X); consigne_0 = joystick_X / 4; //consigne_0 = joystick_X / 5; sprintl(*p0, "%3u", consigne_0); Init_Timer2(); Init_Timer0(); while(cnt0 < (consigne_0 / 10)) { portd.b1 = 0; portd.b0 = 1; // Servomotor LOWER ON. portc.b2 = 1; // LED ON. } portd.b0 = 0; portc.b2 = 0; } if ((joystick_X > 500) && (joystick_X < 524)) { portd.b1 = 0; portd.b0 = 0; portc.b2 = 0; } // Servomotor UPPER 360° : TOWER PRO M996R (360°) (Ancien 270° avec les 2 butées détruites) Init_Timer2(); Init_Timer1(); p1 = &TMR1L; joystick_Y = (ADC_read(1)); // Reads Y axis value with channel 1 (AN1) on pin #3. //if ((joystick_Y <= 500) && (joystick_Y > 250)) if ((joystick_Y <= 490) && (joystick_Y > 250)) { portd.b0 = 0; consigne_1 = 65535 - 1500; // consigne_1 = 65535 - 1500 => 64035 à 65535 = 1500 x 1 uS = 1,5 mS = Ton. // ROTATION CONTINUE GAUCHE LENTE. sprintl(*p1, "%5u", consigne_1); // In Library Manager check box Sprintl and check box C_Type are selected automatically. Delay_ms(1000); // Délais AJUSTABLE pour définir l'angle de rotation. } if ((joystick_Y <= 250) && (joystick_Y > 0)) { portd.b0 = 0; consigne_1 = 65535 - 1750; // consigne_1 = 65535 - 1750 => 63785 à 65535 = 1750 x 1 uS = 1,75 mS = Ton. // ROTATION CONTINUE GAUCHE RAPIDE. sprintl(*p1, "%5u", consigne_1); // In Library Manager check box Sprintl and check box C_Type are selected automatically. Delay_ms(1000); // Délais AJUSTABLE pour définir l'angle de rotation. } //if ((joystick_Y >= 524) && (joystick_Y < 774)) if ((joystick_Y >= 534) && (joystick_Y < 774)) { portd.b0 = 0; consigne_1 = 65535 - 1400; // consigne_1 = 65535 - 1400 => 64135 à 65535 = 1400 x 1 uS = 1,4 mS = Ton. // ROTATION CONTINUE DROITE LENTE. sprintl(*p1, "%5u", consigne_1); // In Library Manager check box Sprintl and check box C_Type are selected automatically. Delay_ms(1000); // Délais AJUSTABLE pour définir l'angle de rotation. } if ((joystick_Y >= 774) && (joystick_Y < 1024)) { portd.b0 = 0; consigne_1 = 65535 - 1250; // consigne_1 = 65535 - 1250 => 64285 à 65535 = 1250 x 1 uS = 1,25 mS = Ton. // ROTATION CONTINUE DROITE RAPIDE. sprintl(*p1, "%5u", consigne_1); // In Library Manager check box Sprintl and check box C_Type are selected automatically. Delay_ms(1000); // Délais AJUSTABLE pour définir l'angle de rotation. } //if ((joystick_Y > 500) && (joystick_Y < 524)) if ((joystick_Y > 490) && (joystick_Y < 534)) //if ((joystick_Y > 250) && (joystick_Y < 774)) { portd.b0 = 0; portd.b1 = 0; portc.b2 = 0; } }
Thanks for your help !
Merci beaucoup.
Eric
--- Updated ---
Last edited by a moderator: