View unanswered posts | View active topics It is currently Mon Dec 22, 2014 5:39 pm






Reply to topic  [ 4 posts ] 
Programing help? 
Author Message
Rookie

Joined: Tue Dec 23, 2008 2:42 pm
Posts: 12
Post Programing help?
There are 2 thing that i would like help on. First Im wondering if you can program a servo to jog every 5 degrees each time you push a button in one direction and push another button to reverse jog 5 degrees. We would like to be able to jog an arm in position a little bit at a time. 2nd How could i control 2 different servos by using 2 different buttons? Like to move servo 1 you have to press btn 6 then to move servo 2 i would like to press btn 11. Hold this isnt to vegue


Thanks


Mon Feb 16, 2009 8:37 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: Programing help?
As far as I know, the servos can't be positioned in terms of "degrees"; they have a range of values from 0-255 that can be assigned thusly (all examples assume a HiTechnic controller chain off of sensor port 1 of Motor Controller->Motor Controller->Servo Controller with a servo, armServo, in slot 1 of the servo controller):
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  none)
#pragma config(Servo,  srvo_S1_C3_1,    armServo,             tServoNormal)

while(true)
{
    servo[armServo] = 123; //Move armServo to position 123
}

To actually move an arm a specific degree measure, you would have to break out the protractor, and through trial and error, determine what value will move the servo 5 degrees.

If we want to increment the position of the servo with each press of a button we could use a global varriable, like this:
Code:
int servoPosition = 0; //Global varriable holding the servo position.
while(true)
{
    if(joy1Btn(1))
    {
        servoPosition++; //Increments position by one
        servo[armServo] = servoPosition; //Set the position of armServo to the value of global variable servoPosition
    }
    if(joy1Btn(2))
    {
        servoPosition += 5; //Increments position by 5
        servo[armServo] = servoPosition; //Set the position of armServo to the value of global variable servoPosition
    }
}


If you want to add another servo your program would look similar to this:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTServo,  none)
#pragma config(Servo,  srvo_S1_C3_1,    armServo,             tServoNormal)
#pragma config(Servo,  srvo_S1_C3_2,    armServo2,            tServoNormal) //Note the declaration of another servo

while(true)
{
    if(joy1Btn(1))
    {
        servo[armServo] = 43;
    }
    if(joy1Btn(2))
    {
        servo[armServo2] = 56;
    }
}


Please note that currently RobotC does not allow for the use of buttons 11 and 12 (or 10 and 11 depending on how you look at it); these are the buttons that would be obtained by pressing (rather hard) on the joysticks. Do not attempt to test for them because you will not get a response, or at least I did not.

Hope this helps, and as a final note, servos can't move anything that is too heavy and would thus be a poor choice to power a heavy arm; better to use a 12v motor.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Mon Feb 16, 2009 11:55 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Programing help?
I agree with Atlantisbase...
Buttons 11 & 12 don't work.

It seems the joystick debugger doesn't actually send them (I'm assuming the FMS doesn't either but I haven't personally tried).

Maybe they didn't think we'd ever possibly need that many buttons. So they left the 2 lines of code required to send them out. :)


Wed Feb 18, 2009 7:43 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: Programing help?
On top of that they are not very useful as buttons as they require a bit of force to activate and you risk pushing the joystick in the process. The only really good use I can see for them is as brakes.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Wed Feb 18, 2009 7:57 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.