Honestly, we should have a whole thread dedicated to people’s questions on coding and programming. This way the forums don’t get cluttered with multiple threads dedicated to simple questions. Also it helps eliminate reposts of questions. Is there a way to make this a sticky?
I would also like to start if off by asking if there is a way to make a parameter for a function to determine whether it is assigned to controller 1 or controller 2. Because at the moment i have this:
void udriving(int controller)
{
if(controller == 1)
{
motor(one) = vexRT[Ch2];
motor(two) = vexRt[Ch2];
motor(three) = vexRT[Ch3];
motor(four) = vexRt[Ch3];
}
if(controller == 2)
{
motor(one) = vexRT[Ch2Xmtr2];
motor(two) = vexRt[Ch2Xmtr2];
motor(three) = vexRT[Ch3Xmtr2];
motor(four) = vexRt[Ch3Xmtr2];
}
}
it seems a bit unnecessary. If there is a better way to do it that would be awesome.
There are always multiple ways to achieve the same result, which one you choose tends to be determined by your coding style and objective in simplifying the code.
One alternative would be for example.
void udriving(int controller)
{
int CtlValueA;
int CtlValueB;
CtlValueA = (controller == 1) ? vexRT Ch2 ] : vexRT Ch2Xmtr2 ];
CtlValueB = (controller == 1) ? vexRT Ch3 ] : vexRT Ch3Xmtr2 ];
motor(one) = CtlValueA;
motor(two) = CtlValueA;
motor(three) = CtlValueB;
motor(four) = CtlValueB;
}
Whether its better is a matter of opinion.
Another alternative would be to create two variables, channel2 and channel3 and assign these in an initialization function.
int channel2;
int channel3;
void init( int controller)
{
channel2 = (controller == 1) ? Ch2 : Ch2Xmtr2;
channel3 = (controller == 1) ? Ch3 : Ch3Xmtr2;
}
then use these instead of Ch2 etc. in the driving routine
void udriving()
{
motor(one) = vexRT channel2 ];
motor(two) = vexRT channel2 ];
motor(three) = vexRT channel3 ];
motor(four) = vexRT channel3 ];
}
out of curiosity you declare “channel 2” as an int but you assign a string to it basically. am i mistaken? i was actually wondering if that last way was possible so thank you for clarifying that. Very Helpful
I’m assigning either Ch2 or Ch2Xmtr2 to channel2, both are effectively integers although defined as enumerated types.
From RobotCIntrinsics.c
typedef enum word
{
//Channels Friendlier Name
Ch1 = 0, vexJSRightH = 0, // Channel 1
Ch2 = 1, vexJSRightV = 1, // Channel 2
Ch3 = 2, vexJSLeftV = 2, // Channel 3
Ch4 = 3, vexJSLeftH = 3, // Channel 4
Ch5 = 4, vexJSChannel5 = 4, // Channel 5
Ch6 = 5, vexJSChannel6 = 5, // Channel 6
//
// Second receiver / transmitter can also be (optionall) connected
//
Ch1Xmtr2 = 6,
Ch2Xmtr2 = 7,
Ch3Xmtr2 = 8,
Ch4Xmtr2 = 9,
Ch5Xmtr2 = 10,
Ch6Xmtr2 = 11,
#if !defined(VEX)
//
// Button Bit Maps
//
//ButtonsXmtr1 = 12,
//ButtonsXmtr2 = 13,
Btn5D = 14,
Btn5U = Btn5D + 1,
Btn6D = Btn5D + 2,
Btn6U = Btn5D + 3,
Btn8D = Btn5D + 4,
Btn8L = Btn5D + 5,
Btn8U = Btn5D + 6,
Btn8R = Btn5D + 7,
Btn7D = Btn5D + 8,
Btn7L = Btn5D + 9,
Btn7U = Btn5D + 10,
Btn7R = Btn5D + 11,
Btn5DXmtr2 = 26,
Btn5UXmtr2 = Btn5DXmtr2 + 1,
Btn6DXmtr2 = Btn5DXmtr2 + 2,
Btn6UXmtr2 = Btn5DXmtr2 + 3,
Btn8DXmtr2 = Btn5DXmtr2 + 4,
Btn8LXmtr2 = Btn5DXmtr2 + 5,
Btn8UXmtr2 = Btn5DXmtr2 + 6,
Btn8RXmtr2 = Btn5DXmtr2 + 7,
Btn7DXmtr2 = Btn5DXmtr2 + 8,
Btn7LXmtr2 = Btn5DXmtr2 + 9,
Btn7UXmtr2 = Btn5DXmtr2 + 10,
Btn7RXmtr2 = Btn5DXmtr2 + 11,
AccelX = 38,
AccelY = AccelX + 1,
AccelZ = AccelX + 2,
AccelXXmtr2 = 41,
AccelYXmtr2 = AccelXXmtr2 + 1,
AccelZXmtr2 = AccelXXmtr2 + 2,
#endif
kNumbOfVexRFIndices,
} TVexJoysticks;
sweet. Thanks for showing me this.
I have another question. How do you code the sensors inside of the joysticks? Like the motion controls?
You can then use the values just as you would any other channel on the joystick.
~Jordan
Do you mean the accelerometers? if so you read them as (for example, it’s incomplete code) …
valuex = vexRT AccelX ];
valuey = vexRT AccelY ];
Otherwise I’m not sure i understand your question.
Woah. You both responded at the exact same time haha
I know, right? I got him beat, though. #ifeelsoaccomplished
~Jordan
But I’m in Los Angeles, Isn’t that 3 hours earlier
btw, Z axis doesn’t work for me, should it?
Smarty – way to get technical.
I’ve never actually tried using the accelerometer in the joysticks. However, I remember seeing this thread quite some time ago.
~Jordan
When programming motors, do positive values turn the motor clockwise or counterclockwise when looking at the screws/black part of the motor? Does positive or negative results change between 269s, 393s, and 3 wires?
I have some of the 393’s and a whole lot of the 3 Wire Motors…
393 – Port #1.
Back of Motor, Negative Number Counter ( Anti ) Clock Wise, Positive Number Clock Wise.
===================================================
393 – Port #2 ( with Motor Controller 29 ) Red<–>Red and Black<–>Black.
Back of Motor, Negative Number Counter ( Anti ) Clock Wise, Positive Number Clock Wise.
393 – Port #2 ( with Motor Controller 29 ) Red<–>Black and Black<–>Red.
Back of Motor, Negative Number Clock Wise, Positive Number Counter ( Anti ) Clock Wise.
===================================================
3 Wire – Port #3.
Back of Motor, Negative Number Clock Wise, Positive Number Counter ( Anti ) Clock Wise.
Yes, UNLESS, you plug the 393 or 269 Backwards into the Motor Controller 29…
[EDIT]
The VEXplorer 2 Wire Motors behave just like the 393’s. On Port #1 or on Port #2 with the Motor Controller 29.
[/EDIT]
Since this a simple programming thread I figured this would be the best place to ask,but what i want to do is put 2 bumper switchs on my robot and when i press one button it runs a certain Automous code and when i hit the other it runs another code i am using easy c i have looked at other threads with the same question and have had trouble idk if im messing the variable up or what
I am trying to recreate a few functions in EasyC for a small project and was wondering if I could get some help. I am trying to figure out exactly what the actual code is behind these 3 functions in EasyC:
Arcade - 2 motor, Holonomic, and Joystick to Digital Latch.
For the first two, I wasn’t sure what mathematical equation EasyC used to calculate the motor values and how it made sure the motors aren’t sent values out of range. As for the third, I’m trying to find a way to recreate it without using any global variables (I’m assuming EasyC doesn’t use globals for it, maybe static locals?) but I’m not sure how to.
Also, what is the result of GetDigitalInput(0)? Does it return 1 or 0 or some kind of error?
Thanks
So you want to write the equivalent of these using EasyC or are you writing in C on another platform?
The Bumper Switch is a Simple Digital Input. So you use Two Inputs, and Two Switches.
In Your Code, how do you want to Implement the Autonomous Section selection??
Can you give a Flow Diagram, Like when and where you check for the Bumper Switch presses.
I want be able to press either bumper 1 or 2 before the autonomous period starts to determine which code runs