View unanswered posts | View active topics It is currently Sun Dec 21, 2014 6:05 pm






Reply to topic  [ 7 posts ] 
Why isn't my servo program functioning? Code included 
Author Message
Rookie

Joined: Thu Nov 29, 2012 9:04 pm
Posts: 7
Post Why isn't my servo program functioning? Code included
Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Hubs,  S2, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S2,     compass,        sensorNone)
#pragma config(Sensor, S3,     light,          sensorLightActive)
#pragma config(Sensor, S4,     sonar,          sensorSONAR)
#pragma config(Motor,  mtr_S1_C1_1,     motorA,        tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S1_C1_2,     motorB,        tmotorTetrix, PIDControl)
#pragma config(Motor,  mtr_S2_C1_1,     motorC,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_2,     motorD,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S2_C2_1,    armServo1,            tServoStandard)
#pragma config(Servo,  srvo_S2_C2_2,    armServo2,            tServoStandard)
#pragma config(Servo,  srvo_S2_C2_3,    clawServo,            tServoStandard)
#pragma config(Servo,  srvo_S2_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#define DEADBAND_THRESHOLD 10       //*!!Define as 10*//
#define BOUND(x) (((x) > 100)? 100: ((x) < -100)? -100: (x))     //*!!Makes sure that the joystick is between -100 and 100 !!*//
#define DEADBAND(x) ((abs(x) >= DEADBAND_THRESHOLD)? x: 0)     //*!!If the joystick is between -10 and 10, it will be treated as 0 !!*//

#define TIME_INTERVAL 100

void arm_servos( int joy2_y1 )
{
   int k = 127;
   if ( DEADBAND(joy2_y1) > 0 )
  {
     servo[armServo1] = k;
     servo[armServo2] = k;
  }
  else
  {
     servo[armServo1] = 0;
     servo[armServo2] = 0;
  }
}

void claw_servo ( int btn2, int btn4 )
{
   int k = 127;
  if ( btn2 == 1 )
   {
      servo[ clawServo ] = k;
   } else
   if ( btn4 == 1 )
   {
      servo[ clawServo ] = 0;
   }
}

#include "JoystickDriver.c"
task main()
{
    while(true)
    {
        getJoystickSettings(joystick); // Update Buttons and Joysticks

        arm_servos( joystick.joy2_y1 );
        claw_servo( joy2Btn(2), joy2Btn(4) );
        wait1Msec(TIME_INTERVAL);
    }
}


Any help or advice would be great! Thank you :)


Thu Dec 06, 2012 12:18 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1372
Post Re: Why isn't my servo program functioning? Code included
Please describe what's not working. What you expect to happen and what is actually happening?


Thu Dec 06, 2012 5:09 am
Profile
Rookie

Joined: Thu Nov 29, 2012 9:04 pm
Posts: 7
Post Re: Why isn't my servo program functioning? Code included
Nothing happens when I press joy2Btn(2) and joy2Btn(4), we checked the wires and everything seems right.


Thu Dec 06, 2012 8:57 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1372
Post Re: Why isn't my servo program functioning? Code included
vincent6liu wrote:
Nothing happens when I press joy2Btn(2) and joy2Btn(4), we checked the wires and everything seems right.

So I take it the armServos worked but the claw servo didn't? If that's the case, it means the joystick controller is working, the servo controller is working, the servo controller is powered. The only conclusion I have is wiring or the servo motor itself. Are you sure the wiring is correct? Did you connect the PWM cable correctly. Did you connect the wire to the correct channel? If you said the armServos are working, then you may want to unplug the armServos and plug the claw servo wire into one of the arm servo channels. Operating the arm joystick and see if the claw works. If that works, try a different channel for the claw servo (channel 4, 5 or 6).
Also make sure you are indeed pressing the correct buttons. Trying pressing other buttons to make sure.


Thu Dec 06, 2012 9:45 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: Why isn't my servo program functioning? Code included
Also, do you have two controllers plugged in? If you're using joy2Btn(), make sure you're pressing buttons on the second controller. You'll have to check the "dual controllers" box in the "Joystick Control - Competition" debugger window and make sure they are properly configured.


Fri Dec 07, 2012 2:42 am
Profile
Rookie

Joined: Thu Nov 29, 2012 9:04 pm
Posts: 7
Post Re: Why isn't my servo program functioning? Code included
We are actually testing the robot with Samantha Field Controller. And we are using two joysticks.
Both armServos and clawServos don't work, and I think the wires are connected right.
So there's nothing wrong with my program?


Fri Dec 07, 2012 9:29 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: Why isn't my servo program functioning? Code included
Make sure that the servo wires are plugged into the controller facing the right way; they'll only work in one orientation, even if they might fit.


Sat Dec 08, 2012 1:30 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.