View unanswered posts | View active topics It is currently Thu Feb 23, 2017 2:39 pm

Reply to topic  [ 2 posts ] 
servo programming 
Author Message

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


#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;
while (true)
motor[motorD] = -joystick.joy1_y2;
motor[motorE] = -joystick.joy1_y1;

else if(joy1Btn(2))
servoTarget(ramp)= RAMP_UP;
/*for (i = 0; i <= 256; i += 16)
servo[ramp] = i;


Thu Nov 08, 2012 12:41 pm

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
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.