ROBOTC Code Help

This is my code

#pragma config(Motor,  port1,           HP393LeftFront, tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port2,           HP393LeftBack, tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port5,           StrafingWheelLeft, tmotorVex393, openLoop)
#pragma config(Motor,  port6,           StrafingWheelRight, tmotorVex393, openLoop)
#pragma config(Motor,  port7,           LiftRight,     tmotorVex393, openLoop)
#pragma config(Motor,  port8,           LiftLeft,      tmotorVex393, openLoop)
#pragma config(Motor,  port9,           HP393RightFront, tmotorVex393, openLoop)
#pragma config(Motor,  port10,          HP393RightBack, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main ()
{

  while(1 == 1)
  {
    motor[HP393LeftFront] = vexRT[Ch2];
    motor[HP393LeftBack] = vexRT[Ch2];
    motor[HP393RightFront] = vexRT[Ch3];
    motor[HP393RightBack] = vexRT[Ch3];
    motor[StrafingWheelLeft] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[StrafingWheelRight] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[LiftLeft] = (vexRT[Btn5UXmtr2] - vexRT[Btn5DXmtr2]);
    motor[LiftRight] = (vexRT[Btn6UXmtr2] - vexRT[Btn6DXmtr2]);
  }

}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

When I download the code, the arm doesn’t lift with the Partner Joystick. What am I doing wrong? How do I get the Partner joystick to be able to lift the arm? There are 2 393’s on the arm, in ports 7/8.

Personally - i would not have done this like this … i would have done the drive like this, but the lift as an if statement …

Look at the possible values of the buttons. Hopefully you can take it from there. You’ll probably say Doh! once you figure it out. You are pretty close now.

http://www.robotc.net/wiki/VEX2_Functions_Remote_Control_-_VEXnet#Btn5UXmtr2

You also have a bunch of 393 motors all allowed to be at high power. You may want to limit that a bit to avoid tripping the breakers. Distribution of the motors across ports is also advisable.

Tripping the breakers is not fun. You can enjoy watching your robot stay nice and motionless at a critical point in the match without some limits. Yeah!

I don’t really know a lot about ROBOTC, so could you change the program I have, to what you would use?

Thanks!

#pragma config(Motor,  port1,           HP393LeftFront, tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port2,           HP393LeftBack, tmotorVex393, openLoop, reversed)
#pragma config(Motor,  port5,           StrafingWheelLeft, tmotorVex393, openLoop)
#pragma config(Motor,  port6,           StrafingWheelRight, tmotorVex393, openLoop)
#pragma config(Motor,  port7,           LiftRight,     tmotorVex393, openLoop)
#pragma config(Motor,  port8,           LiftLeft,      tmotorVex393, openLoop)
#pragma config(Motor,  port9,           HP393RightFront, tmotorVex393, openLoop)
#pragma config(Motor,  port10,          HP393RightBack, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main ()
{

  while(1 == 1)
  {
    motor[HP393LeftFront] = vexRT[Ch2];
    motor[HP393LeftBack] = vexRT[Ch2];
    motor[HP393RightFront] = vexRT[Ch3];
    motor[HP393RightBack] = vexRT[Ch3];
    motor[StrafingWheelLeft] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
    motor[StrafingWheelRight] = (vexRT[Btn6U] - vexRT[Btn5U])*127;
   if(vexRT[Btn5UXmtr2] == 1)
{
  motor[LiftRight] = 100; 
  motor[LiftLEft]  = 100; 
}

if(vexRT[Btn5DXmtr2] == 1)
{
  motor[LiftRight] = -100;
  motor[LiftLeft] = -100
}
  }

}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Something like this?

Looks like you have some *127 missing in your original code.

Close too. But you don’t set the motors to 0 when both buttons are off. So it will stay on once you press the button. There’s a good example on the robotc joystick page.

http://www.robotc.net/wiki/VEX2_Functions_Remote_Control_-_VEXnet#vexRT

OK, I got it to work!

I will post the code later when I am on the laptop.

I’m also going to change the power setting for the motors like you suggested.+

Thank you!

I’m glad you got this to work properly. If you want to learn more about ROBOTC coding, I’d suggest checking out our online video trainer:

http://www.education.rec.ri.cmu.edu/products/teaching_robotc_cortex/index.html

It walks you through coding step-by-step, but you can jump to whatever section you need help with. For example, we have a three-part tutorial that actually deals with exactly what you ran into under the Remote Control->Buttons section (Controlling the Arm parts 1-3).

Enjoy, and let us know if you run into any other issues!

with if statements … always remember there needs to be an else statement or an else if statement … other wise it will carry on forever … without stopping, and good going on your attempt, i normally use if statement, because i can do the following

#pragma config(Sensor, in1, p1, sensorPotentiometer)
#pragma config(Sensor, dgtl1, l1, sensorTouch)
#pragma config(Motor, port1, , tmotorVex269, openLoop, reversed)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

task main()
{
while(1==1)
{
if(vexRT[Btn5D] == 1)
{
if(SensorValue[l1] == 0)
{
if(SensorValue[p1] <180)
{
motor[port1] = 127;
}
else
{
motor[port1] = 0;
}
}
}
}
}

  • we are using lots of sensors on the arm for autonomous … so we decided to put a limit on the user control as well … useful !

Er, no. else is completely optional.

This is the syntax from K&R (admittedly old, shoud be ANSI C really).

Edit
Ok, I see what you were trying to say and I misunderstood.

You meant that there needs to be a condition where the motor can be stopped, this is correct. I thought you were talking about C code syntax. My bad.

No worrys, and yeh, an else statement would be needed


  while(1 == 1)
  {
   
    motor[LiftLeft] = (vexRT[Btn5UXmtr2] - vexRT[Btn5DXmtr2]);
    motor[LiftRight] = (vexRT[Btn6UXmtr2] - vexRT[Btn6DXmtr2]);
  }

}

The problem with the original code is that buttons have a value between 0 and 1 (0 for not pressed, 1 for pressed). The motor] function sets the power level of the motors, (a range between -127 and +127) thus, by pressing the button would set the power level to 1, which is waaaaaayyy too slow to move anything. If you wanted the code to work with your original format, multiply each statement by 127 (At least I think it would work)