View unanswered posts | View active topics It is currently Thu Dec 18, 2014 7:25 pm






Reply to topic  [ 5 posts ] 
Programming a motor to act like a servo 
Author Message
Rookie

Joined: Sat Nov 22, 2008 7:14 pm
Posts: 12
Location: NJ
Post Programming a motor to act like a servo
Our group wants me to program the nxt motors to act like a servo. I am not sure how to go around with that so they zero out on a position and then using the joystick to change the angle, does anyone know how to program that?

_________________
Ethan Spitz
Team 464 Programmer


Sat Nov 22, 2008 7:18 pm
Profile
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: Programming a motor to act like a servo
well, you could just do 1 of two things.

1. Program the servos straight to the joysticks.
servo[servo1] = (joystick function);

2. Set the servos to a variable where the joystick value "adds" to the position so that the servo doesn't move back when the joystick is centered.

int a;
servo[servo1] = a + (joystick function);


Sat Nov 22, 2008 8:43 pm
Profile
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
Post Re: Programming a motor to act like a servo
Quote:
Our group wants me to program the nxt motors to act like a servo.


They want an nxt motor to act as a servo, not use a servo sunny.
try using an encoder function. nxt encoders are 360 ticks per revoplution. dowside is that you need to know which way you want the motor to go. ill attach some code tomorow as i dnt hv time rt now.
hope this helps

_________________
PHUHS Robotics
Team 516 FTW

Daytona Robofest Winning Alliance Captain
Daytona Robofest Inspire Award


Mon Nov 24, 2008 12:53 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: Programming a motor to act like a servo
The trick with using an NXT motor as if it were a servo is to remember that you can't just tell it to go to a particular position. You can, however, tell it to go either forward or backwards until the encoder reaches a particular count. You also do not have any way of asking what position the motor is in at the start of your program. So, you will want to ensure that you move the motor by hand to a known starting position before starting your program. Let's say, as an example, that you want to call the starting position 0. That makes things easy. Just define a function like so:

Code:
void SetMotorToPos(int mtr, int pos)
{
    motor[mtr] = 0;

    if (nMotorEncoder[mtr] == pos)
        return;

    nMotorEncoderTarget[mtr] = pos;
    if (nMotorEncoder[mtr] < pos)
        motor[mtr] = -25;
    else
        motor[mtr] = 25;

}


task main()
{
    nMotorEncoder[motorA] = 0;

    // Move the "servo" back or forth every second.
    while (true)
    {
        SetMotorToPos(motorA, 100);
        wait10Msec(100);
        SetMotorToPos(motorA, 200);
        wait10Msec(100);
    }
}

_________________
Jeff McBride
Benson Robotics Club


Mon Nov 24, 2008 1:31 pm
Profile
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: Programming a motor to act like a servo
My mistake, I read the question wrong. I through they wanted to control the servo with a joystick or something. :D.


Mon Nov 24, 2008 6:02 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.