White Paper Discuss: C Programming and Autonomous Modes for Newbies

Thread created automatically to discuss a document in the White Papers.

C Programming and Autonomous Modes for Newbies by cbolin

Congratulations, Chuck–I guess it takes a South Carolinian to speak to a South Carolinian. This is the first programming white paper that actually clicked with me. (I’m not a programmer by any stretch. But I guess that’s obvious).

One question, on the line tracking example in the autonomous notes…at Position D, when the left sensor is made, shouldn’t the robot turn to the left instead of the right?

But other than that, bravo!

I read this yesterday morning. I thought it was great also. I sent him a PM with my thanks.
I didn’t notice this error yesterday but now reading it again I do see it. It seems like he messed up that whole section.

Here is what I think It should look like:


//place this line before **while (autonomous_mode).**
**	unsigned char s_left = rc_dig_in01;**
**	unsigned char s_middle = rc_dig_in02;**
**	unsigned char s_right = rc_dig_in03;**
//place this after** Getdata(&rxdata);**
**if (s_left == 0 && s_middle == 1 && s_right == 0) **
**// Middle sensor on**
**// Go straight**
**{**
**	pwm01=160; //left motor**
**	****pwm02=160; //right motor**
**}**

**else if (s_left == 1 && s_middle == 1 && s_right == 0) **
**// Left 2 sensors on**
**// Turn soft Left**
**{**
**	****pwm01=127; //left motor**
**	pwm02=160; //right motor**
**}**

**else if (s_left == 1 && s_middle == 0 && s_right == 0) **
**// Left sensor on**
**// Turn Hard Left**
**{**
**	****pwm01=127; //left motor**
**	pwm02=180; //right motor**
**}**

**else if (s_left == 0 && s_middle == 1 && s_right == 1) **
**// Right 2 sensors on**
**// Turn soft right**
**{**
**	****pwm01=160; //left motor**
**	****pwm02=127; //right motor**
**}**

**else if (s_left == 0 && s_middle == 0 && s_right == 1) **
**// Right Sensor on**
**// Turn Hard Right**
**{**
**	****pwm01=180; //left motor**
**	pwm02=127; //right motor**
**}**

**else 	 //stop**
**{**
**	****pwm01=127; //left motor**
**	pwm02=127; //right motor**
**}**

The other error I saw was in Table 3 First Row, First Column (on the bottom of page 5), that should be Turn Left. The numbers and diagram is still correct

Again, Great Job Chuck

I am a newbie; this is my first year in FRC. I know how to program in many other languages, but C is a new one for me. If anyone has any tips or advice on programming for a newbie, I’d be much obliged.:smiley: All I have to learn it at home is a college textbook…I’m a freshmen in High School! Anyway, any help would be greatly appreciated. Thanks!