View unanswered posts | View active topics It is currently Wed Oct 01, 2014 6:24 am






Reply to topic  [ 10 posts ] 
Advanced servo positioning 
Author Message
Rookie

Joined: Fri Apr 08, 2011 9:16 am
Posts: 11
Post Advanced servo positioning
[b]i hated when i push the button, the servo move to a specific position, and when i'm released, it went back to the original position.
so i was wondering if there's any way that after i release the button, the servo will stay in the position and not return some position.
[/b]


Fri Apr 08, 2011 9:24 am
Profile
Rookie

Joined: Fri Apr 08, 2011 9:16 am
Posts: 11
Post Re: Advanced servo positioning
//assume btn 6 & 8 are the buttons controlling the servos//
//servo 1 & 2 are the servos i need to position//
#include "JoystickDriver.c"
task main()
{
if(joy1Btn(6))
{
servo(servo1) = servo(servo2) = 120;
}
else
{
servo(servo1) = ServoValue(servo1);
servo(servo2) = ServoValue(servo2);
}
if(joy1Btn(8))
{
servo(servo1) = servo(servo2) = 5;
}
else
{
servo(servo1) = ServoValue(servo1);
servo(servo2) = ServoValue(servo2);
}
}
this is what i have so far, but i have no idea if this is going to work.


Fri Apr 08, 2011 9:29 am
Profile
Site Admin
Site Admin

Joined: Mon Jun 08, 2009 4:50 pm
Posts: 70
Post Re: Advanced servo positioning
Hi 3325,

One way that might be even more simple would be to remove the 'else' clauses all together:

Code:
//assume btn 6 & 8 are the buttons controlling the servos//
//servo 1 & 2 are the servos i need to position//
#include "JoystickDriver.c"
task main()
{
  if(joy1Btn(6))
  {
    servo(servo1) = servo(servo2) = 120;
  }
 
  if(joy1Btn(8))
  {
    servo(servo1) = servo(servo2) = 5;
  }
 
}


This way the servo gets a command to go to the position when a button is pressed, but is not given any commands for what to do when the button is not pressed, thus it stays put.
I do like the way you did it though, it's very complete-but not simple.

Anyway I hope that you get it working,

_________________
Bence Feher

Undergraduate Intern - NREC, Robotics Academy
ROBOTC - Testing/Documentation/Developer

Computer Science, Japanese, East Asian Studies
University of Pittsburgh, Konan University 甲南大学


Fri Apr 08, 2011 10:25 am
Profile
Rookie

Joined: Fri Apr 08, 2011 9:16 am
Posts: 11
Post Re: Advanced servo positioning
thanks, but doesn't that mean if i press and release the buttons, the servo will only turn to those two positions instead of stopping when i released the buttons?


Fri Apr 08, 2011 8:00 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Advanced servo positioning
The value you assigned to a servo is the angle position, not power. So if you set a number, the servo will go there and stop by itself. It should not have anything to do with when you are releasing the button. In your previous code, you set them to zero and that will make the servo go back to the 0-position when you released the button. Also, you still don't need the else part of your code. Once the servo is set to a position, it will hold it there until you change the number again. You don't need to assign the same number to it over and over again. Are you saying you need to set a servo to a position and want to abort before it gets there? I am not aware a way to do it unless you implement your own servo with motor and encoder.


Fri Apr 08, 2011 11:41 pm
Profile
Rookie

Joined: Fri Apr 08, 2011 9:16 am
Posts: 11
Post Re: Advanced servo positioning
That's not the case here, what I want is after I program the servo I can manually control the servo to whatever position I want not just any prearranged values, I want to have the ability to program the servo so that it will stop at any value I want within it's range, even though I not sure if it is possible.


Mon Apr 11, 2011 12:36 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Advanced servo positioning
I am not sure I understand what you need. If you want to manually control a servo to go to whatever angle you want, for example using a joystick position to translate to servo position, it is possible to do so. Assuming your servo has a range of 0-degree to 180-degree. You can translate the full range of the joystick y-axis to servo angle by the following code.
Code:
servo[servo1] = ((joystick.joy1_y1 + 128)*180)/256;

Or if you want to use buttons to "step the servo up or down" similar to your previous code, you can do the following:
Code:
#define MIN_POS         0
#define MAX_POS         180
#define DELTA_POS       1
task main()
{
    int pos = MIN_POS;

    while (true)
    {
        if (joy1Btn(6))
        {
            pos += DELTA_POS;
            if (pos > MAX_POS)
            {
                pos = MAX_POS;
            }
        }
        else if (joy1Btn(8))
        {
            pos -= DELTA_POS;
            if (pos < MIN_POS)
            {
                pos = MIN_POS;
            }
        }
        servo[servo1] = pos;
        servo[servo2] = pos;
        wait1Msec(10);
    }
}

The above code will allow you to press and hold button 6 to start the servos in one direction. As soon as you release button 6, they will stop. If you press and hold button 8, they will swing in the opposite direction. If you release the button, they will stop. In both cases, the servos will not go beyond their range.


Mon Apr 11, 2011 2:44 am
Profile
Rookie

Joined: Fri Apr 08, 2011 9:16 am
Posts: 11
Post Re: Advanced servo positioning
Thanks I'll Check it out today


Tue Apr 12, 2011 12:27 pm
Profile
Rookie

Joined: Fri Apr 08, 2011 9:16 am
Posts: 11
Post Re: Advanced servo positioning
hmmm, how can i say this
it doesn't seems to be working at all when i pressed the buttons,
still need help


Wed Apr 27, 2011 9:43 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Advanced servo positioning
What is not working? When you pressed the button, nothing moved? If so, the first thing to check is if your game controller is working and connected. Make sure you have your game pad dialog opened on your RobotC IDE. When you pressed any of the gamepad buttons does the button value in the dialog changed? If it doesn't, the game controller is not even recognized. If it does, then you need to check if the NXT received the joystick messages by adding the following code. If it does show the correct button number, then it should work. Otherwise, press some other buttons to see if you got the button number wrong and so on.
Code:
task main()
{
    int pos = MIN_POS;

    while (true)
    {
        if (joy1Btn(6))
        {
            nxtDisplayTextLine(3, "Btn=6");
            pos += DELTA_POS;
            if (pos > MAX_POS)
            {
                pos = MAX_POS;
            }
        }
        else if (joy1Btn(8))
        {
            nxtDisplayTextLine(3, "Btn=8");
            pos -= DELTA_POS;
            if (pos < MIN_POS)
            {
                pos = MIN_POS;
            }
        }
        servo[servo1] = pos;
        servo[servo2] = pos;
        wait1Msec(10);
    }
}


Wed Apr 27, 2011 11:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.