|
calzim
Rookie
Joined: Fri Dec 30, 2011 4:18 pm Posts: 3
|
 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
|
|
amcerbu
Novice
Joined: Sun Oct 21, 2012 10:01 pm Posts: 76
|
 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.
|