View unanswered posts | View active topics It is currently Sun Oct 20, 2019 12:46 pm






Reply to topic  [ 3 posts ] 
Servos are randomly moving when using joystick drive. 
Author Message
Rookie

Joined: Wed Feb 11, 2015 8:37 pm
Posts: 1
Post Servos are randomly moving when using joystick drive.
We are driving a tetrix bot with two motors for our drive. Each motor is set to a joystick y-axis. When they drive our servos start to randomly move. Here is the code I have -

#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, HTMotor)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, touch, sensorTouch)
#pragma config(Sensor, S3, light, sensorLightActive)
#pragma config(Sensor, S4, sonar, sensorSONAR)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop, driveRight, encoder)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop, reversed, driveLeft, encoder)
#pragma config(Motor, mtr_S1_C3_1, motorF, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_2, motorG, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, motorH, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C4_2, motorI, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoStandard)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoStandard)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoStandard)
#pragma config(SrvoPosition, Position03, 78, 180, 0, 122, 0, 0, 0, 0)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++++

2 Joystick Drive
- This program allows you to remotely control your robot using the USB Logitech Dual
Action Joysticks.
- For USB values to be transmitted to the robot, you must follow several steps:
- Use the "#include "JoystickDriver.c"" line at the beginning of your program
- Call the "getJoystickSettings(joystick);" in a loop to repeatedly retrieve the latest values
- Open the Robot > Debugger Windows > "Joystick Control - Basic" window after downloading your
program to the virtual robot

Robot Model(s): TETRIX Ranger

[I/O Port] [Name] [Type] [Description]
mtr_S1_C1_1 rightMotor TETRIX Motor Right side motor
mtr_S1_C1_2 leftMotor TETRIX Motor Left side motor, reversed

----------------------------------------------------------------------------------------------------*/

#pragma debuggerWindows("joystickSimple");
#include "JoystickDriver.c"

task main()
{
waitForStart();
while(1 == 1)
{
//Get the Latest joystick values
getJoystickSettings(joystick);
//Set the driving motors equal to the Y-axis values of the joysticks
servo[servo1] = joystick.joy2_y1 + 78; //this controls grippers on our arm
servo[servo2] = joystick.joy2_y2 * -1 + 180;
motor[motorE] = joystick.joy1_y1 / 4; //this controls drive
motor[motorD] = joystick.joy1_y2 / 4;

//this allows our robot to go full speed because its geared up.
if(joy1Btn(7) == 1)
{
motor[motorE] = joystick.joy1_y1;
motor[motorD] = joystick.joy1_y2;
}
//this controls servos on the back that both go down. they face opposite of each other so the values are different.
if(joystick.joy1_TopHat == 0)
{
servo[servo3]=0;
servo[servo4] = 113;

}
else if(joystick.joy1_TopHat == 4)
{
servo[servo3]=106;
servo[servo4] = 8;
}

if(joystick.joy2_TopHat == 0) //this contols our arm going up and down
{
motor[mtr_S1_C3_1] = 25;
motor[mtr_S1_C4_1] = 25;
}
else if(joystick.joy2_TopHat == 4)
{
motor[mtr_S1_C3_1] = -25;
motor[mtr_S1_C4_1] = -25;
}
else
{
motor[mtr_S1_C3_1] = 0;
motor[mtr_S1_C4_1] = 0;
motor[mtr_S1_C3_2] = 0;
}
}
}

We have one daisy chain of controllers that goes motor controller, servo controller, motor controller, motor controller.


Wed Feb 11, 2015 8:55 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Servos are randomly moving when using joystick drive.
Code:
servo[servo1] = joystick.joy2_y1 + 78; //this controls grippers on our arm
servo[servo2] = joystick.joy2_y2 * -1 + 180;


I'm assuming that this is the problematic code; the issue you are running into is that the joysticks very rarely are actually dead center with a value of 0, even when released. The reason for this is due to the physical design of the joysticks but is one case where you can overcome a physical limitation with code. To do so, you will need to create a 'deadband' of values that are ignored by the code you are using to assign values to the servos.

This is actually pretty simple to do; you simply need to check to see if the joysticks are within your 'deadband' range before assigning the calculated value to the servo. For example:

Code:
   //Create an integer to store our deadband value (15)
   int deadband = 15;

   //If the joystick's absolute value is greater than the deadband
   //(outside of the deadband range)
   if(abs(joystick.joy2_y1) > deadband)
   {
      //Set the servo's value with the calculated value
      servo[servo1] = joystick.joy2_y1 + 78; //this controls grippers on our arm
   }
 
   //If the joystick's absolute value is greater than the deadband
   //(outside of the deadband range)
   if(abs(joystick.joy2_y2) > deadband)
   {
      //Set the servo's value with the calculated value
      servo[servo2] = joystick.joy2_y2 * -1 + 180;
   }


You may need to tweak the values being calculated and the deadband variable to suit your specific needs, but this is one way to help eliminate the servo 'noise' that is occurring.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Mon Feb 16, 2015 1:16 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post Re: Servos are randomly moving when using joystick drive.
Please be more specific about your problem. The answer above could be the solution to your problem, but many other things may need to be accounted for. When the servos move, have you sent any commands to them yet? Try initializing them before your tele-operated period begins. 359 has, in the past, had troubles concerning if we had not set the servos to any positions and we sent commands to motor controllers with a higher chain index than the servo controller, the servos on it would move. Due to not being set beforehand, these servos would have timed out (gone neutral) and when they receive power when trying to send commands to the connected motor controllers, they would move as well.


Thu Feb 19, 2015 1:25 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 0 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.