View unanswered posts | View active topics It is currently Mon Dec 10, 2018 7:24 am






Reply to topic  [ 3 posts ] 
Location Tracker for NXT Robot Using nMotorEncoder 
Author Message
Rookie

Joined: Sun Feb 15, 2015 12:07 pm
Posts: 4
Post Location Tracker for NXT Robot Using nMotorEncoder
Hey everyone,

For a school project, I am creating a robot that is controlled by a Logitech controller. I have already coded the controller part, but I want to include a feature that returns the robot to the original location automatically when a button is pressed on the controller. The only way I can do this is using the nMotorEncoder to track the location of the robot relative to the original location. When it is going straight forward at speeds of 100 for both motors, I know that I can calculate the distance traveled by doing nMotorEncoder[motorA] * PI * r / 180.

I am stuck on the turning portions however. I'm not sure what equation to use to calculate the heading and distance traveled by the robot during the turns. When turning, the motors are always at a 1/10 ratio (one motor is at 10 speed while the other is at 100). Here is the code for the controller portion if it helps. My plan is to calculate the heading and distance travelled during each time the loop is passed, and then updating the general location relative to the original position. Here is my code so far:

Code:
#include "JoystickDriver.c"
#pragma DebuggerWindows("joystickSimple")

const int FULL = 100, SLOW = 10;

void setMotorSpeeds(int aSpeed, int cSpeed) {
   motor[motorA] = aSpeed;
        motor[motorC] = cSpeed;
}

int checkForMove() {
         //none
    if(joystick.joy1_x1 / 10 == 0 && joystick.joy1_y1 / 10 == 0 ) {
            setMotorSpeeds(0,0);
            return 0;
      }
    //forward
    else if(joystick.joy1_y1 > 0) {
          //left
          if(joystick.joy1_x1 < -45) {
                setMotorSpeeds(SLOW,FULL);
                return 1;
          }
          //forward
          else if (joystick.joy1_x1 < 45) {
                 setMotorSpeeds(FULL,FULL);
                 return 2;
            }
          //right
          else {  //joystick.joy1_x1 > 0
                setMotorSpeeds(FULL,SLOW);
                return 3;
            }
      }
      //backward
    else if(joystick.joy1_y1 < 0) {
          //left
          if(joystick.joy1_x1 < -45) {
                setMotorSpeeds(-SLOW,-FULL);
                return 4;
            }
          //forward
          else if (joystick.joy1_x1 < 45) {
                setMotorSpeeds(-FULL,-FULL);
                  return 5;
            }
          //right
          else { //joystick.joy1_x1 > 0
                setMotorSpeeds(-FULL,-SLOW);
                  return 6;
            }
      }
      else {
            setMotorSpeeds(0,0);
            return 0;
       }
}

task main() {
     while(1 == 1) {
          getJoystickSettings(joystick);

          checkForMove();
      }
}


Any help would be greatly appreciated. If you need clarification, please ask. I know that this question is kind of weird, but I really want to do this the right way instead of just doing trial by error.

Thanks!


Sun Feb 15, 2015 12:17 pm
Profile
Rookie

Joined: Thu Feb 19, 2015 10:24 am
Posts: 3
Post Re: Location Tracker for NXT Robot Using nMotorEncoder
I am interested to know if you ever figured out this problem? I am trying to work a similar feature into my robot. Please let me know how it works out for you.


Thu Feb 19, 2015 2:35 pm
Profile
Rookie

Joined: Sun Feb 15, 2015 12:07 pm
Posts: 4
Post Re: Location Tracker for NXT Robot Using nMotorEncoder
Unfortunately I couldn't think of a way to make it work in the short timeline that I have, so I have ditched the project idea.


Thu Mar 05, 2015 5:24 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.