|
Skyviper
Rookie
Joined: Tue Jan 13, 2009 12:24 pm Posts: 10
|
 Re: servo problem please help
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none) #pragma config(Hubs, S2, HTMotor, none, none, none) #pragma config(Hubs, S4, HTServo, none, none, none) #pragma config(Motor, mtr_S1_C1_1, RR, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, LR, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C2_1, LF, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S1_C2_2, RF, tmotorNormal, PIDControl, encoder) #pragma config(Motor, mtr_S2_C1_1, shoot, tmotorNormal, openLoop) #pragma config(Motor, mtr_S2_C1_2, load, tmotorNormal, openLoop) #pragma config(Motor, motorA, idle, tmotorNormal, PIDControl, encoder) #pragma config(Servo, srvo_S4_C1_1, aim, tServoNormal) #pragma config(Servo, srvo_S4_C1_2, trig, tServoNormal) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
///////////////////////////////////////////////////////////////////////////////////////////////////// // // Tele-Operation Mode Code Template // // This file contains a template for simplified creation of an tele-op program for an FTC // competition. // // You need to customize two functions with code unique to your specific robot. // /////////////////////////////////////////////////////////////////////////////////////////////////////
#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
///////////////////////////////////////////////////////////////////////////////////////////////////// // // initializeRobot // // Prior to the start of tele-op mode, you may want to perform some initialization on your robot // and the variables within your program. // // In most cases, you may not have to add any code to this function and it will remain "empty". // /////////////////////////////////////////////////////////////////////////////////////////////////////
void initializeRobot() { // Place code here to sinitialize servos to starting positions. // Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.
return; }
///////////////////////////////////////////////////////////////////////////////////////////////////// // // Main Task // // The following is the main code for the tele-op robot operation. Customize as appropriate for // your specific robot. // // Game controller / joystick information is sent periodically (about every 50 milliseconds) from // the FMS (Field Management System) to the robot. Most tele-op programs will follow the following // logic: // 1. Loop forever repeating the following actions: // 2. Get the latest game controller / joystick settings that have been received from the PC. // 3. Perform appropriate actions based on the joystick + buttons settings. This is usually a // simple action: // * Joystick values are usually directly translated into power levels for a motor or // position of a servo. // * Buttons are usually used to start/stop a motor or cause a servo to move to a specific // position. // 4. Repeat the loop. // // Your program needs to continuously loop because you need to continuously respond to changes in // the game controller settings. // // At the end of the tele-op period, the FMS will autonmatically abort (stop) execution of the program. // /////////////////////////////////////////////////////////////////////////////////////////////////////
task main() { initializeRobot();
waitForStart(); // wait for start of tele-op phase
while (true) { /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// //// //// //// Add your robot specific tele-op code here. //// //// //// /////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// Insert code to have servos and motors respond to joystick and button values.
// Look in the ROBOTC samples folder for programs that may be similar to what you want to perform. // You may be able to find "snippets" of code that are similar to the functions that you want to // perform.
// shooter controls
int motorloadrunning = 0; if(joy2Btn (6)) // load { motor[load] = -60; motorloadrunning = 1; }
if(joy2Btn (3)) // reverse load for ball jam { motor[load] = 30; motor[shoot] = 100; motorloadrunning = 1; } if(joy2Btn (8)) // load for shooting { motor[load] = -30; motorloadrunning = 1; }
if (motorloadrunning == 0) { motor[load]= 0; }
if(joy2Btn (9)) // shoot { motor[shoot] = -100; motor[idle] = -100; } if(joy2Btn (10)) // shooter stop { motor[shoot] = -0; motor[idle] = 0; } if(joy2Btn(7)) // aim shooter { servo[aim] = 100; servo[trig] = 10; } if(joy2Btn(5)) // trigger to hold balls { servo[trig] = 150; servo[aim] =20; }
if(joy2Btn(4)) // increase angle { servo[aim] += 2; wait1Msec(100); }
if(joy2Btn(2)) // increase angle { servo[aim] -= 2; wait1Msec(100); }
/////////////////////////////// base programming
if(abs(joystick.joy1_y1)>10) { motor[RR]= (int)(((float)joystick.joy1_y1/127.0)*100.0); motor[LF]= (int)(((float)-joystick.joy1_y1/127.0)*100.0); } else { motor[RR]= 0; motor[LF]= 0; }
if(abs(joystick.joy1_x1)>10) { motor[RF]= (int)(((float)-joystick.joy1_x1/127.0)*100.0); motor[LR]= (int)(((float)joystick.joy1_x1/127.0)*100.0); } else { motor[RF]= 0; motor[LR]= 0; }
while(joy1Btn(6)) //while button 6 on joystick 1 is pressed turn robot right / clocwise { motor[RR]=-100;//right turn motor[LF]=-100;//right turn motor[RF]=-100;//right turn motor[LR]=-100;//right turn } while(joy1Btn(3)) //strafe right {
motor[RF]=-25;// motor[LR]=25;// } while(joy1Btn(1)) //strafe left {
motor[RF]=25;// motor[LR]=-25;// } while(joy1Btn(5)) //while button 5 on joystick 1 is pressed turn left or counter clockwise { motor[RR]=100;//left turn motor[LF]=100;//left turn motor[RF]=100;//left turn motor[LR]=100;//left turn }
while(joy1Btn(8)) //while button 6 on joystick 1 is pressed turn robot right / clocwise { motor[RR]=-25;//right turn motor[LF]=-25;//right turn motor[RF]=-25;//right turn motor[LR]=-25;//right turn } while(joy1Btn(7)) //while button 5 on joystick 1 is pressed turn left or counter clockwise { motor[RR]=25;//left turn motor[LF]=25;//left turn motor[RF]=25;//left turn motor[LR]=25;//left turn }
} }
thats our drive program, we added more servos now so we really need to know how come its doing what its doing. if i take the servo trig out of the lines on that button it still moves around with that button
and if i write a simple code that says if i press button 3 servo aim goes to this position, THEY ALL DO and i didnt even define them at the top. help please i dont know why this is happening
|
|
amarts
Rookie
Joined: Wed Feb 24, 2010 11:19 am Posts: 8
|
 Re: servo problem please help
We just had the same problem. Don't understand what happened, but not being able to use the servo controller as the 4th controller on sensor port 1, we had it on sensor port 4 (like you). We competed at our regional and when we got back home, the servos wouldn't move.
We tested new servos, replaced the servo controller, tried a second NXT, and created a clean program using the telop template with only the servo controller on port 4 and only code to move servo 1. It still didn't work. Next we moved the servo controller to sensor port 1 and it worked. It worked on port 2 as well.
So, we ended up moving the servo controller to sensor port 2 and the light sensor in port 2 to port 4. All is fine now. Still don't understand why it quit working on port 4 though.
Andy
|