View unanswered posts | View active topics It is currently Tue Jul 29, 2014 2:41 am






Reply to topic  [ 2 posts ] 
servo programming 
Author Message
Rookie

Joined: Fri Dec 30, 2011 4:18 pm
Posts: 3
Post servo programming
we are trying to program a servo on one of the joy stick buttons. we got the servo to work without the joy stick but adding the joy stick we get a servo out of range error

here is the code, any help would be great, thanks

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

#pragma config(Hubs, S1, HTMotor, none, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop)
#pragma config(Servo, srvo_S2_C1_1, ramp, tServoStandard)
#pragma config(Servo, srvo_S2_C1_2, servo2, tServoNone)
#pragma config(Servo, srvo_S2_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S2_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S2_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S2_C1_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

const int RAMP_DOWN=255;
const int RAMP_UP = 128;
//TJoystick joystick;

task main()
{
//int i;
//servo(ramp)=160;
while (true)
{
getJoystickSettings(joystick);
motor[motorD] = -joystick.joy1_y2;
motor[motorE] = -joystick.joy1_y1;

if(joy1Btn(4))
{
servoTarget(ramp)=RAMP_DOWN;
}
else if(joy1Btn(2))
{
servoTarget(ramp)= RAMP_UP;
}
/*for (i = 0; i <= 256; i += 16)
{
servo[ramp] = i;
wait1Msec(50);
}
*/
}
}

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


Thu Nov 08, 2012 12:41 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: servo programming
First of all, you can use the [code] and [/code] tags to display fixed-width, indented text.

Anyway, the problem is this: you can only send a servo a number between 0 and 255. The analog sticks on the Logitech controllers return values from -128 to 127. So, you have to set the servo's position to the joystick value + 128.


Fri Nov 09, 2012 10:05 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.