View unanswered posts | View active topics It is currently Sat Jul 26, 2014 3:07 am






Reply to topic  [ 2 posts ] 
Can't get this to work 
Author Message
Rookie

Joined: Sat Nov 17, 2012 10:27 pm
Posts: 5
Post Can't get this to work
Ok, i'm trying to program my controller to an tetrix arm, which is powered by a motor. But the motor is too powerful, so I tried to change the programming, but it turned out all weird. when I make a the motor turn one way, it keeps on turning in the same direction, and even when i tried to put in something to stop it, it still goes one way. Can anyone tell me what i'm doing wrong so I can correct it? Thanks!
-Lincoln



Code:
#include "JoystickDriver.c"

task main()
{
  while(true)
  {
    getJoystickSettings(joystick);

    while((joystick.joy1_y2)>0)
    {
       motor[motorD] =10;
    }
    while((joystick.joy1_y2)<-2)
    {
       motor[motorD] =-10;
    }
    while((joystick.joy1_y2)==-1)
    {
       motor[motorD] =0;
    }
  }
}


Sat Nov 17, 2012 10:38 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: Can't get this to work
One of the main problems you might be having is that joysticks don't always settle back to (0, 0) when they're released. Every controller is slightly different, the springs are slightly more worn in some places than others. You usually can't count on joystick values under 10 being very reliable (unless you're holding the stick yourself). Also, your code uses while loops, which I'm pretty sure are not what you want.

Try this code (leave your #pragmas alone, I'm just doing task main()):

Code:
int threshold = 20;
float scale = 2.0;  // Adjust this number to fit the speed you want

task main()
{
   while (true)
   {
      getJoystickSettings(joystick);

      if (abs(joystick.joy1_y2) > threshold)
         motor[motorD] = joystick.joy1_y2 / scale;
      else
         motor[motorD] = 0;
   }
}


You said the motor was "too powerful." I assume it was moving too quickly. Be mindful that reducing the number you send to a motor reduces both its speed and its power. I'd suggest using gear ratios to increase the torque and decrease the speed at which the arm rotates.


Sat Nov 17, 2012 11:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.