View unanswered posts | View active topics It is currently Mon Oct 20, 2014 9:43 am






Reply to topic  [ 3 posts ] 
Servos and Joysticks 
Author Message
Rookie

Joined: Thu Nov 19, 2009 1:21 pm
Posts: 11
Post Servos and Joysticks
Hello Folks!
We are a new team and trying to get the hang of RobotC. We are doing okay with the motor work, but having trouble getting going with the servo controls.
Our problem is this: we can get the servors to move when we push a button, but only a full range trip.

if(joy1Btn(3) ==1)
{
servoTarget[Arm] = 180;
servoChangeRate[Arm] = 1;
}
if(joy1Btn(4) == 1)
{
servo[Claw] = 198;
}
if(joy1Btn(2) == 1)
{
servo[Claw] = 140;
}
}

We want to control our servos with a change rate, so instead of the arm going all the way down, it goes down 10 every time we push it.
Does that make sense? I have found lots of autonomous programming info online, but is there a good FTC teleop resource for programming a controller?
Thanks!


Thu Nov 19, 2009 2:43 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3225
Location: Rotterdam, The Netherlands
Post Re: Servos and Joysticks
Moved to more appropriate forum.

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]


Thu Nov 19, 2009 2:47 pm
Profile WWW
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 139
Post Re: Servos and Joysticks
Based on your post, I assume that you want to move the servo a small amount on each press of a button which would not require you to interact with the changeRate which controls how quickly the servo moves to a new position.

The basic approach I've seen to this is to set the servo target to the current value plus an incremental step.
For example:

Code:
//max value we want the servo to move
const int ARM_MAX_RANGE = 198;
//min value we want the servo to move
const int ARM_MIN_RANGE = 0;
//how many degrees to move at a time
const int ARM_STEP_SIZE = 10;

if(joy1Btn(3)) //button 3 to move up
{
   if(servoValue[Arm] < (ARM_MAX_RANGE - ARM_STEP_SIZE))
   {
      //move arm up by one step
      servoTarget[Arm] = servoValue[Arm] + ARM_STEP_SIZE;
   else
   {
      //if step would exceed max; set to max
      servoTarget[Arm] =ARM_MAX_RANGE;   
   }
}
else if(joy1Btn(4)) //button 4 to move down
{
   if(servoValue[Arm] > (ARM_MIN_RANGE + ARM_STEP_SIZE))
   {
      //move arm up by one step
      servoTarget[Arm] = servoValue[Arm] - ARM_STEP_SIZE;
   else
   {
      //if step would exceed min; set to min
      servoTarget[Arm] =ARM_MIN_RANGE;
   }
}

Please note that I have not tested the code above.
Also note that care is taken to avoid moving the servo beyond the intended range. Another thing you will have to contend with is holding the button down may shoot through the loop and end up instantly setting you to your min or max targets. You may have to either use a variable to control moving in and out of the if statements or move the code into another task with a delay.


Fri Nov 20, 2009 1:02 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.