Simple Programming Questions

I have a quick question about the variables float and double, i understand that they are used for decimal numbers but i dont completely under stand one thing, in the help menu of easy c it says this

i do not completely understand the ranges but i was wonder if it can hold a somewhat simple number like 2.5 or is it only for numbers with alot of decimal places like in the examples and with only a small number like 1 in the examples or is it just for use of any decimals.

Float stands for floating point. And yes it can store small numbers and decimal values.

It’s actually a complicated type that can assign bits to either an exponent or value. This has the effect of moving the point (the dot).

It can approximately store most real numbers, but you should know that it can create rather problematic rounding errors.

Apparently “90.1000” in C (don’t know which version), will come out as “90.0999.”

This would be very bad if we were checking the value, so in general you shouldn’t be using floats or doubles directly in conditional statements (ifs). Either round them or check that the value is within a reasonable range (foo<91 && foo>90).

Hope that helps, also see my PROS video on datatypes for some more info.

Help is always appreciated… :slight_smile:

It is, so please help me and stop posting trivial responses to hundred of threads. I know you are excited to have just had your account unlocked, please respect the other users of the forum and slow down a bit.

Hello everyone,
So we have been trying to get some help with our code and so we figured we would post our question here since this is a programming section and it may help someone else later. Anyways, I have been looking through the forums and seen some advice on what we want to do but since I am a very new programmer, I need a little more assistance. A lot of it makes sense but I have had to teach myself everything about programming so I do not have a very extensive knowledge yet.

So, that being said, what we would like to do is have a potentiometer that runs something like four different programs for autonomous based on where the potentiometer is positioned. I also want to use one bumper switch to do something extra in each autonomous option we have. For example, in the boxes closest to the goals, we hope to knock the first big ball off, come back, reposition, go forward, knock the second ball off, then come back. After that, I would like to have a limit switch I could press and send the robot over to the goal to toss in a bucky. I tried integrating that in to my first code on the file a bit already but most likely did it wrong. I have already written some code using Easy V4 Cortex block functions but when we try and run the autonomous, the robot does not do anything. I have the code posted on Mediafire at:
http://www.mediafire.com/download/xb...N'_Large.BDS

I am not sure if the Mediafire thing will work because I have never used it before but I figured it would be worth a shot. For some reason, my computer will not let me copy and paste the code so someone said Mediafire would be an alternate way to go about it.

If this does not work and I did another thing wrong :o, I can always try and do something different as I have my code with me. If worst comes to worst, maybe I could just send pictures through our bot’s instagram page? We have done this a few times already with other teams and it can work.

Also, I am trying to figure out how to run pneumatics during autonomous. We have two single acting pistons that are connected to ports 9 and 10 that I would like to engage during the autonomous period.

Any help with this stuff would be greatly appreciated. Even the little things that may seem very easy to some we struggle with so any advice is very much appreciated. Thanks again!

Does anyone have a sample code on EasyC ? For lets say:

Button one = A program
Button two = A program
Button Three = A program
Button four= A program
Button Five= A program

All being different autonomuses

Solution here.
https://vexforum.com/showpost.php?p=354639&postcount=6

Specify one variable (unsigned char) each for each bumper switch.
Next you need to put a while loop with value 1 inside the autonomous template. Inside the while loop, go to inputs on the left bar and select bumper switch. Specify digital output 1 and return its value to the variable you created for that bumper switch. Next use an if function in such a way
If ( your variable for switch == 0 )
{
Run the autonomous for that button
}

Repeat the same procedure for each bumper switch

What does #pragma mean or stand for?

Thank you

It’s a symbol that tells the compiler to skip the line while telling the pre-processor some useful information.

There are always multiple ways to achieve the same result

This is probably a completely simple question, but is there any way in RobotC to convert an integer value into a string value?

use sprintf.

char  str[32];
int    foo = 12;

sprintf(str,"%d", foo );

We are having a lot of trouble with the potentiometer and getting it to work and easyC. The && (but) isn’t working and only one of them runs. Does someone have like a video or pictures of there If statements in easyC that would be amazing!

I don’t know easyC, but I’m going to take a wild guess that && is a boolean (logical) AND.

Yes, && means AND (in easyC and RobotC). BotZillas: If you would post your code, we might be able to help you.

I’m working in EasyC V5 to balance two sides of my scissor lift with Optical Quad Encoders. Currently I just call my entire ArmControl() function in operator control so I have everything in this function with the exception of startin g the QuadEncoders. When turned on the arm just moves downwards. Here’s my code, any help would be appreciated.


// ARM.c : implementation file
#include "Main.h"

// TODO: add user code here

void ArmControl(int targetPosition)
{
    while (1)
    {
    Holonomic ( 1 , 3 , 4 , 1 , 2 , 4 , 1 , 3 , 1 , 1 , 0 , 1 ) ;
    JoystickDigitalToMotor ( 1 , 5 , 1 , 127 , 2 , -127 , 9 ) ;
    JoystickDigitalToMotor ( 1 , 5 , 1 , 127 , 2 , -127 , 10 ) ;
    long LeftPosition = GetQuadEncoder ( 1 , 2 ) ; 
    long RightPosition = GetQuadEncoder (3 , 4 ) ;
    int up = GetJoystickDigital ( 1 , 5 , 1 ) ;
    int down= GetJoystickDigital ( 1 , 5 , 2 ) ;
    int direction = 1;
    int Goal;
    PrintToScreen ( "Left:%d\n" , LeftPosition ) ; 
    PrintToScreen ( "Right:%d\n" , RightPosition ) ;
    if ( up == 1 )
    {
           Goal = targetPosition + 500;
    }
    if ( down == 1)
    {
            Goal = targetPosition - 500;
            direction = -1;
    }
    else
    {
            Goal = targetPosition;
    }
     
    int delta = Goal - targetPosition;
    int correctionL = Goal - LeftPosition;
    int correctionR = Goal - RightPosition;
    if( correctionR < 50 && correctionR > -50) {correctionR = 0;}
    if( correctionL < 50 && correctionL > -50) {correctionL = 0;}
    
    
    
    SetMotor( 5 , (1 - correctionL / delta) * 127 * direction);
    SetMotor( 6 , (1 - correctionL / delta) * 127 * direction);
    SetMotor( 7 , (1 - correctionR / delta) * -127 * direction);
    SetMotor( 8 , (1 - correctionR / delta) * -127 * direction);
    
    Wait ( 25 ) ; 
    
    }
}

This will not be a good solution, however I think once the autonomous starts you could press the button still and not get dq’d. This is because when you are hooked up to the field controller the robot’s program has not been started and its I/O is being blocked. This is why you cannot move the robot until the matches start and when they are over. In the auton function you could simply put:


task autonomous()
{
	bool RedAuton = false;
	bool SensorTouched = false;
	while(!SensorTouched)
	{
	    SensorTouched = SensorValue(BlueButtonSensor) == 1 ||
	        SensorValue(RedButtonSensor) == 1; 
	    RedAuton = SensorValue(RedButtonSensor) == 1;
	}
	if(RedAuton)
	{
	    RunRedAuton();
	}
	else
	{
	    RunBlueAuton();
	}
}


void RunBlueAuton(){
...
}
void RunRedAuton(){
...
}

Can someone post a robotc x drive code.

Look here

Next time please start your own thread.