View unanswered posts | View active topics It is currently Thu Aug 21, 2014 10:08 am






Reply to topic  [ 6 posts ] 
Servos with two controllers 
Author Message
Rookie

Joined: Tue Oct 07, 2008 9:51 pm
Posts: 6
Post Servos with two controllers
can anyone show me how to create a program to control three servos and two dc motors on two controllers? (motors on one and servos on the other)

here's what i have so far
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     right,         tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     left,          tmotorNormal, openLoop)
#pragma config(Servo,  servo1,          lower_arm_right,      tServoNormal)
#pragma config(Servo,  servo2,          lower_arm_left,       tServoNormal)
#pragma config(Servo,  servo3,          middle_arm,           tServoNormal)
#pragma config(Servo,  servo4,          bucket,               tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

task main()
{
   while (true)
   {
        getJoystickSettings(joystick);
        motor[left] = joystick.joy1_y1;
         motor[right] = joystick.joy1_y2;
   }
  while (true)
  {
    getJoystickSettings(joystick);

      if(joy2Btn(4) !=0);
       {
         servoTarget[lower_arm_right] = 150;
       }
       if(joy2Btn(2) !=0)
       {
         servoTarget[lower_arm_right] = 0;
       }
       if(joy2Btn(4) !=0);
       {
         servoTarget[lower_arm_left] = 150;
       }
       if(joy2Btn(2) !=0);
       {
         servoTarget[lower_arm_left] = 0;
       }
       if(joy2Btn(5) !=0);
       {
         servoTarget[middle_arm] = 150;
       }
       if(joy2Btn(7) !=0)
       {
         servoTarget[middle_arm] = 0;
       }
       if(joy2Btn(6) !=0)
       {
         servoTarget[bucket] = 150;
       }
       if(joy2Btn(8) !=0)
       {
         servoTarget[bucket] = 0;
       }
   }
}
//Admin Edit for readability

we need this ASAP

if you can tell me what is wrong would be GREAT!!! or if you want to fix it go ahead!


Last edited by 118steelhornets on Tue Nov 04, 2008 9:55 am, edited 2 times in total.



Mon Nov 03, 2008 11:04 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: Servos with two controllers
Sounds like you are doing this for FTC, Im going to move this over to that topic section B-)

Scott

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Mon Nov 03, 2008 4:41 pm
Profile WWW
Rookie

Joined: Fri Oct 24, 2008 1:25 pm
Posts: 14
Post Re: Servos with two controllers
in the brackets after servotarget you need to say which servo you want to move unless the name you have in the bracket is the name you gave it. is it? if so just put in: servo# (#=the # of servo) and see if that works :wink: :bigthumb:


Wed Nov 05, 2008 3:18 pm
Profile
Novice

Joined: Thu Oct 09, 2008 7:58 pm
Posts: 79
Post Re: Servos with two controllers
Uh, 2 things.

1. When you post, try and keep the formatting and use whitespace. It helps the people who are trying to help you.

2. it seems like you have 2 while(true) statements...the 2nd while statement won't run...unless it's some sort of tasking thing that IDK about.


Wed Nov 05, 2008 9:04 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: Servos with two controllers
Change this:
Code:
task main()
{
while (true)
{
getJoystickSettings(joystick);
motor[left] = joystick.joy1_y1;
motor[right] = joystick.joy1_y2;
}
while (true)
{
getJoystickSettings(joystick);

if(joy2Btn(4) !=0);
...


to this:

Code:
task main()
{
while (true)
{
getJoystickSettings(joystick);
motor[left] = joystick.joy1_y1;
motor[right] = joystick.joy1_y2;

if(joy2Btn(4) !=0)
...


Also note that your if() statements that have semicolons on the end are not going to do what you expect.

_________________
Jeff McBride
Benson Robotics Club


Thu Nov 06, 2008 12:06 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 602
Post Re: Servos with two controllers
Also getting rid of the "!= 0" and just leaving statements as "joy1Btn(btn)" may help as well.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Nov 06, 2008 4:36 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.