View unanswered posts | View active topics It is currently Sat May 27, 2017 12:26 am

Reply to topic  [ 3 posts ] 
Servos with the controller 
Author Message

Joined: Thu Nov 19, 2009 1:21 pm
Posts: 11
Post Servos with the controller
Here is our code, there are no errors. The robot shakes because the program is continually cycling through the if statements, if we go through step by step it will work. However our question is why is it executing the code in the if statements if no buttons are pressed?

#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorLeft, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorRight, tmotorNormal, openLoop, reversed)
#pragma config(Servo, srvo_S1_C2_1, ScoopLeft, tServoNormal)
#pragma config(Servo, srvo_S1_C2_2, ScoopRight, tServoNormal)
#pragma config(Servo, srvo_S1_C2_3, Gate, tServoNormal)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
#pragma config(SrvoPosition, Down, 224, 32, 128, 128, 128, 128, 128, 128)
#pragma config(SrvoPosition, Up, 100, 146, 128, 128, 128, 128, 128, 128)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

task main()


if(joy1Btn(1)); // If button 1 is pressed
servo[ScoopLeft] = 100;
servo[ScoopRight] = 146;

servoChangeRate[ScoopLeft] = 0;
servoChangeRate[ScoopRight] = 0;


if(joy1Btn(2)); // If button 2 is pressed
servo[ScoopLeft] = 224;
servo[ScoopRight] = 32;

servoChangeRate[ScoopLeft] = 5;
servoChangeRate[ScoopRight] = 5;


if(joy1Btn(3)); // If button 3 is pressed
servo[Gate] = 60;

servoChangeRate[Gate] = 5;


if(joy1Btn(4)); // If button 4 is pressed
servo[Gate] = 128;

servoChangeRate[Gate] = 5;




Fri Dec 18, 2009 9:01 pm
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Servos with the controller
Hey there,

If there were no errors, surely it would work as intended? :)

I am not familiar with the workings of the servos (I don't own a controller), but I noticed that you have code for when a button is pressed, but no code for when no buttons are pressed. Do you not need to stop the servos when you are not pressing any buttons at all? Could this be the source of your problems?


| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Sat Dec 19, 2009 2:21 am
Profile WWW

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Post Re: Servos with the controller
Enhance your program to add counters to the code in the "IF" statements to count how many times the code is executed. Then examine the values of the counters with the debugger to see if they are expected.

Try changing the "servoChangeRate" to zero instead of five and see if that corrects the problem. It shouldn't, but just check anyway. If it does solve the problem, post away.

But what I suspect is happening is the following:
  • You're using the servos to control a lifting arm and bucket.
  • The servos aren't really strong enough for the task.
  • When you reach a position, the servo applies a light "load" to hold in place.
  • Gravity causes the arm to lower.
  • After enough movement the servo in the arm applies enough "load" to cause the servo to move back to the hold position.
You can "cure" this type of problem with using two servos in parallel to provide twice as much holding power.

Another alternative explanation is that load on the servos is so heavy that the internal thermal overload is periodically kicking in and disabling either the servos or the HiTechnic controller. When the overload detector cools off it resets and the servo starts working again.

If you connect an unloaded servo instead of the actual servos connected to your lifting arm do you still get the jerking? If it disappears with the unloaded servos then it would point towards one of the above causes.

Another possible explanation is that you have the servo controller on one sensor port and the motor (or other servo controllers) on another sensor port. Instead of all devices on one sensor port. This can apparently create "Ground Loops" -- i.e. an electrical problem; one of the symptoms of ground loops is spurious servo pulses sent by the Servo Controller.

Sat Dec 19, 2009 5:32 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

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.