BEST Robotics Forum
Register Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
snidbert64

Junior Member
Registered:
Posts: 4
Reply with quote  #1 
---PROBLEM SOLVED DO NOT REPLY---

I use RobotC and have as long as I have been my team's lead programmer.
Unfortunately, I have encountered an issue where a program for our claw is not working for no apparent reason.
One version of the program moved the claw when the triggers were pressed (which was what I wanted), while another program that had the same claw task did not. In both versions of the code, the claw task was the only place where the clawServo is mentioned.


0
jgraber

Moderator
Registered:
Posts: 112
Reply with quote  #2 

Whatever bracket style that is, it makes it too long to see a useful amount on one page.

Many of your comments are useless and cluttery, like these... they add zero meaning
task main() // define the task main
a = 0; //initialize a to zero

I see you like trinaries; me too; it avoids that terrible bracket spacing.

As for the text of your question,
Unfortunately, I have encountered an issue where a program is not working for no apparent reason.
Right now, our robot is currently only a claw, so I'm only getting output on the claw.
But as far as I have seen, this code works:
I don't understand what you are saying:
"not working" is meaningless, what did you expect it to do? what does it do instead of that?

See http://www.catb.org/esr/faqs/smart-questions.html

If you dont get timely answers here, you might try vexforum.com robotC forum;
They have a much larger, more active userbase, as well as a VP of RobotC.

I have cleaned up the comments and brackets, so the code is more readable,
and I used CODE <> markers instead of "" quote markers, see if this is more readable.   Well, all the indenting is still lost.

Note that code like these two lines:
if( vexRT[Ch3] == 0) { // If the left stick is not moved on the y-axis-
if( vexRT[Ch1] == 0 && vexRT[Ch2] == 0 ) { // If the right stick is not moved ------
depends on the stick being zeroed exactly, which is called ' no deadband '
usually a deadband of 5 or 10 will be more useful, since perfectly zeroed sticks are rare.

Code:

#pragma config(Motor, port5, clawServo, tmotorNormal, openLoop) //Claw servo: clawServo, port 5.
#pragma config(Motor, port6, latchServo, tmotorNormal, openLoop) //Copper Cart servo: , port 6.

int full_power_mode = 1;
float arm_grad = 0.0;
float r_wheel = 0.0;
float l_wheel = 0.0;

task dustpan() {
while (true) {
if( vexRT[Btn7U] + vexRT[Btn7D] == 1) {
motor[port4] = vexRT[Btn7D] == 1 ? 100 : -100;
} else {
motor[port4] = 0;
}
} // wend
} // task dustpan

task arm() {
while (true) { // Set the power of the port 7 motor (arm) to minus the value
if( vexRT[Ch3] == 0) { // If the left stick is not moved on the y-axis-
if( arm_grad != 0) {
arm_grad = arm_grad - 0.25;// Subtract 0.25 from the value of "arm_grad"
}
} else { // If the left stick is moved on the y-axis -
if( arm_grad != 1) {
arm_grad = arm_grad + 0.25;// Add 0.25 to the value of "arm_grad"
}
}
motor[port7] = vexRT[Ch3] * arm_grad; // of the transmitter Channel 3 (how much the left stick
} // wend is tilted on the y-axis) times "arm_grad".
} // task arm

task F_P_M() {// Define the task which concerns the full power mode.
while(true){
// Basically what this // While the 7D button is not pressed -
// it waits until the 7D button is pressed.
while(vexRT[Btn7L] == 0) { sleep(0);}
// it waits until the 7u button is pressed.
while(vexRT[Btn7L] == 1) { sleep(0);}
// basically toggles turbo mode on/off
full_power_mode = full_power_mode * -1 ;
} // wend
} // end task F_P_M Full Power Mode

task C_C_L(){ // Define the task which concerns the copper cart latch
motor[latchServo] = -65;
while(true) {
//Copper cart servo controlled by left triggers (button group 5)
motor[latchServo] = motor[latchServo] + vexRT[Btn5D] * 10;
motor[latchServo] = motor[latchServo] - vexRT[Btn5U] * 10;
if(motor[latchServo] < -65){motor[latchServo] = -65;}
if(motor[latchServo] > 111){motor[latchServo] = 111;}
} // wend
} // end task CCL Copper Cart Latch

task claw() {
motor[clawServo] = 0;
while(true) {
motor[clawServo] += (vexRT[Btn6D] - vexRT[Btn6U]);
sleep(5);
} // wend
} // end task claw

task main() {
startTask(claw);
startTask(dustpan);
startTask(C_C_L);
startTask(F_P_M);
float gradient = 0.0;
int vexRTCh1 = 0;
bMotorFlippedMode[port9] = true; // Port 9 (right wheel) reversed
startTask(arm);

while(true){
// If the absolute value of Channel 1 (right stick y-axis) is greater than 15 (more than 15 in either direction), set
vexRTCh1 = abs(vexRT[Ch1]) > 15 ? vexRT[Ch1] : 0; // "vexRTCh1" to the value of Channel 1. Otherwise, set it to zero.
if( vexRT[Ch1] == 0 && vexRT[Ch2] == 0 ) { // If the right stick is not moved ------
if( gradient != 0){ gradient = gradient - 0.25; }
} else { // If the right stick is moved ------------
if( gradient != 1) { gradient = gradient + 0.25; }
}
r_wheel = (vexRT[Ch2] * .7 - vexRTCh1 / -2) * gradient; // Right stick y-axis value: forward/backward motion
l_wheel = (vexRT[Ch2] * .7 + vexRTCh1 / -2) * gradient; // Right stick x-axis value: left/right steering
r_wheel = full_power_mode == 1 ? r_wheel * -2 : r_wheel * -.7; // Adjust the values of "r_wheel" and "l_wheel",
l_wheel = full_power_mode == 1 ? l_wheel * -2 : l_wheel * -.7; // depending on whether turbo mode is active.
// Set the power of the motors on ports 2 and 9 (the wheels) to "l_wheel" and "r_wheel",
// respectively, unless the variable in question is greater than the maximum of 127.
motor[port9] = abs(r_wheel) > 127 ? full_power_mode == 1 ? r_wheel > 127 ? 127 : -127 : 65 : r_wheel;
motor[port2] = abs(l_wheel) > 127 ? full_power_mode == 1 ? l_wheel > 127 ? 127 : -127 : 65 : l_wheel;

} // wend
} // end task main

0
snidbert64

Junior Member
Registered:
Posts: 4
Reply with quote  #3 
Thanks for replying! I am horrible at explaining things. The point is, when trying to code the claw, the code in the original post moved the claw when the triggers were pressed, while another program that had the same claw task did not. In both versions of the code, the claw task was the only place where the clawServo is mentioned.
0
jgraber

Moderator
Registered:
Posts: 112
Reply with quote  #4 
> I am horrible at explaining things. 
Engineering jobs required better communication, so it would be good to work on that.
Clear communication shows clear thinking, etc

You have to post the code that doesn't work to get help with it.

The usual suggestions for getting help on a forum for a programming problem:
1 Describe what you want it to do
2 Describe what is does instead
3 Show that you have tried to solve the problem yourself,  by saying things you have already tried.
4 Post the actual code, preferably trimmed to the smallest program that demonstrates the problem
 Many times when removing other tasks, etc, and verifying that the problem still exists, you will find the solution yourself.

In this case,  Keep just the main task while commenting out start task on all other tasks except claw.
 and keep claw task.   remove the other tasks from your code.   See if it still has the same problem.

These are just generic programming problem suggestions.
The RobotC forum on the Vexforum.com will have the best advice for RobotC specific problems.




0
snidbert64

Junior Member
Registered:
Posts: 4
Reply with quote  #5 
Thank you for your time.
The RobotC forums, last time I checked, were read-only.
I don't plan on being an engineer. I plan on being an indie video game developer.
If I delete every task except the claw, it works. If I delete any one individual task, it doesn't work, but the robot will be more than a claw.
I don't know how to ask for help online; this is basically my last resort before just rebuilding the code from scratch.
In fact, I might just do that.
Bye...?
0
jgraber

Moderator
Registered:
Posts: 112
Reply with quote  #6 
I just checked vexforum.com  > Technical Support > Robot C   and I was able to click New Conversation and get a text box.
I didn't actually enter a question to see if it barfed later.
You do have to register and login to that forum system to post though.
If not the Robot C forum,  then unofficial tech support or just tech topics would be fine.
Only paid people can answer official tech support forums, so it is very slow compared to peer support in the unofficial channels.

   Rewrite from scratch will often work.
It seems like every job uses programming these days, particularly game developers.
When changing things to see what works,  it is always easier to go from working code,  and add one more thing,
than to go from nonworking code, and try one fix, because there is often more than one thing wrong at a time,
or an interaction between things. 
  So when you have a working claw code,  try uncommenting one more task and test that.

I'm trying to teach you how to ask for help online.
  Posting the code that doesn't work is the first step.


0
snidbert64

Junior Member
Registered:
Posts: 4
Reply with quote  #7 
I figured it out. Sorry for wasting your time!
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation: