View unanswered posts | View active topics It is currently Fri Sep 19, 2014 2:01 am






Reply to topic  [ 10 posts ] 
Semi-Novice Programmer - I need help! 
Author Message
Rookie
User avatar

Joined: Sat Feb 14, 2009 5:59 pm
Posts: 22
Post Semi-Novice Programmer - I need help!
Alright. Our robot is working great but my team (how do I put it) reconstructed our robot and now I need to have code for tomorrow. I know how to do a good 70% of what our coach wants but there are some extra things that I know I will need help with.

So here they are:

1 - Arcade mode (we currently have both of controller 1's joysticks mapped in a crude version of 'tank mode')

2 - FULL servo control with a joystick (my code currently allows the servo to rotate halfway)

_________________
Lead Programmer for Team COV-0651.


Fri Feb 27, 2009 4:32 pm
Profile
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
Post Re: Semi-Novice Programmer - I need help!
for servos add 127 to the joy value

_________________
PHUHS Robotics
Team 516 FTW

Daytona Robofest Winning Alliance Captain
Daytona Robofest Inspire Award


Fri Feb 27, 2009 7:02 pm
Profile
Rookie
User avatar

Joined: Sat Feb 14, 2009 5:59 pm
Posts: 22
Post Re: Semi-Novice Programmer - I need help!
Really? It's that simple? wow....

_________________
Lead Programmer for Team COV-0651.


Fri Feb 27, 2009 7:50 pm
Profile
Novice

Joined: Mon Oct 13, 2008 6:29 pm
Posts: 75
Location: Florida, USA
Post Re: Semi-Novice Programmer - I need help!
m hm, servos accept values from 0-255, joystick goes from -127 to +127

_________________
PHUHS Robotics
Team 516 FTW

Daytona Robofest Winning Alliance Captain
Daytona Robofest Inspire Award


Fri Feb 27, 2009 10:51 pm
Profile
Rookie

Joined: Fri Jan 02, 2009 9:13 pm
Posts: 10
Post Re: Semi-Novice Programmer - I need help!
We used arcade mode, so I can help you out there, here is some code you can modify for your use:

motor[drive_right] = joystick.joy1_y1 - joystick.joy1_x1;
motor[drive_left] = joystick.joy1_y1 + joystick.joy1_x1;

Edit: Just realized I was probably too late. Hope you figured it out in time :)


Sun Mar 01, 2009 3:47 am
Profile
Rookie
User avatar

Joined: Sat Feb 14, 2009 5:59 pm
Posts: 22
Post Re: Semi-Novice Programmer - I need help!
Don't worry about it - I now have to deal with NXT-G because my team didn't think I had a good enough handle with coding in RobotC.

I hate GUI programming (except RoboLab for the RCX).

Also, just for the hell of it, how do you program a servo that's mounted backwards? We are trying to lift an arm with two servos that are mounted like this: d b.

I thought that if the code said:
Code:
servoTarget[servoARMLEFT] = joystick.joy2_x1 + 127; //rotate bucket arm forward with the joystick (servo rotates clockwise)
servoTarget[servoARMRIGHT] = joystick.joy2_x1 - 127; //rotate bucket arm forward (servo rotates counterclockwise)

that it would turn the servos in the same direction. It does, but when we want to bring our arm back to the original position it only goes halfway.

_________________
Lead Programmer for Team COV-0651.


Mon Mar 02, 2009 12:24 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Semi-Novice Programmer - I need help!
try this for two opposing servos moving the same thing.

lets say we have two servos SERVO_A and SERVO_B. We are going to set the value of SERVO A manually and set the value of SERVO_B automatically.

Code:
 servo[SERVO_A] = joystick.joy2_x1 + 127;
 servo[SERVO_B] = 255 - ServoValue[SERVO_A];


this works because in the background RobotC ramps the servo positions up and down smoothly (which is a good thing or you'd have to do it yourself)

ServoValue[...] gives the current actual position of the servo (or more accurately the position RobotC firmware is actually commanding it to go to)

Since the servos are in backwards we use the 255-x to approximate the best position for the tracking servo.

Note 1: This isn't perfect as no two servos are exactly the same. The servo's will fight each other a little bit so you'll lose some torque
and waste some battery, but it'll probably work good enough.

Note 2: Run your code BEFORE and WHILE you attach the servos. Make sure they are being held at position X and 255-X then mechanically attach the servo horns.

Note 3: The only 100% fullproof way to do this is to use a multimeter on SERVO_B to find an exact value Y for every position of SERVO_A where the servo current is minimal. This is when the two servos are at the same ANGLE and they won't be fighting each other. Put this in a big array and use it to lookup what the value of SERVO_B should be for a given value of SERVO_A.

I was able to reduce the servo motor current by 100-500mA (depending on position) by doing this. But I've met enough people that think doing things right is overkill or "too advanced" so I gave the easy way out first.


Mon Mar 02, 2009 12:38 pm
Profile
Rookie
User avatar

Joined: Sat Feb 14, 2009 5:59 pm
Posts: 22
Post Re: Semi-Novice Programmer - I need help!
Code:
servo[SERVO_B] = 255 - ServoValue[SERVO_A];

So this code basically tells RobotC reverse the values of SERVO_B according to those from SERVO_A?

Pretty fricken sweet.

_________________
Lead Programmer for Team COV-0651.


Mon Mar 02, 2009 3:05 pm
Profile
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Semi-Novice Programmer - I need help!
yep. thats the idea.

make sure you run it in a loop to keep refreshing the current value of SERVO_A (remember RobotC is changing it in the background).
The same loop as where you set SERVO_A will normally be okay for manual mode since you're setting it to joystick values.

If you use this in autonomous mode you'll have to figure out where to loop it...otherwise use this form:
Code:
servo[SERVO_A] = x;
servo[SERVO_B] = 255-x;


Also remember this is just the commanded position of the servo not the actual position. I tried to contact Hitechnic to tell them a way to read the ACTUAL position of the servo, but they didn't seem interested.... why would they be since they have a total monopoly (even more than RobotC). Their system can't even turn the servos off once you send the first reposition command. And they didn't seem interested in fixing this either, and its only a software change.


Mon Mar 02, 2009 3:55 pm
Profile
Rookie
User avatar

Joined: Sat Feb 14, 2009 5:59 pm
Posts: 22
Post Re: Semi-Novice Programmer - I need help!
I find it extremely funny how RobotC provides an option to reverse the DC motors but not the servos.

"reverse the servos? Why would anyone want to do that?" :lol:

_________________
Lead Programmer for Team COV-0651.


Mon Mar 02, 2009 4:11 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.