View unanswered posts | View active topics It is currently Mon Sep 22, 2014 10:44 am






Reply to topic  [ 4 posts ] 
Servo Increment 
Author Message
Rookie

Joined: Wed Oct 05, 2011 2:49 pm
Posts: 12
Post Servo Increment
So I'm having issues getting my servo's to increment. It wants to jump all the way to 255. As if as soon as I hit button 1, the if statement is engaged permanently and the position continues incrementing all the way up to the max.
Thoughts?


I have my L_Pinch servo initialized to 0.
It's embedded within
task main()
while(true)

if (joystick.joy1_Buttons == 1)
{
servo[L_Pinch] += 5;
}


Mon Oct 10, 2011 2:43 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Servo Increment
Is this the complete program?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Oct 10, 2011 3:04 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Servo Increment
The program is probably doing what you want it to, but it's just doing it too fast. If you have no wait time between the if statement, then as soon as you press the button, the processor is so fast that the servo value goes to max before you can blink. I seem to recall that ROBOTC has a servo change rate variable in the servo debugger, but I could be wrong. If not, you can use a simple bit of code to slow down the servo. Here's an example:
Code:
task main(){
  while(true){
    getJoystickSettings(joystick);
    if(time1[T1] > 50){
      if(joystick.joy1_Buttons){
        servoValue[L_Pinch] += 5;
      }
      ClearTimer(T1);
    }
  }
}


This will only check and update the servo every 50ms without interrupting your other functions with lag. You can change the 50 to make the servo move faster or slower. Hope that helps.

_________________
sudo rm -rf /


Last edited by magicode on Mon Oct 10, 2011 4:42 pm, edited 1 time in total.



Mon Oct 10, 2011 3:35 pm
Profile
Rookie

Joined: Wed Oct 05, 2011 2:49 pm
Posts: 12
Post Re: Servo Increment
I was thinking about the timing issue. I solved it differently though.

if (joyBtn(4))
{
servo[L_Pinch] = ServoValue[L_Pinch] + 5;
}

I found that the servo[] command is to set the value and servovalue[] reports the value.
So if servo[] = servo[] + 5, then somehow the iterative loop fails the system.
Thanks for the responses.


Mon Oct 10, 2011 3:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.