I have been coding for the whole day today, there were failures but also accomplishments. Failures in coding makes you fell like you been struggle in a math problem, you have the right idea for solution of the problem, but you just can get it right. Today, I was working on the remote controlling code with my robots, but the robots just simply not working and I have completely no clue what is wrong with it. The software that I was programming with called Robot C, which is developed by Carnegie Mellon University for developing robot programming. And this software drives me crazy. My program passed every single compile, and It has absolutely no problem on the logic, but whenever I want to have it run on my robot, it is just simply not working. Here is how I wrote my program:
#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, none)
#pragma config(Hubs, S2, HTServo, none, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorleft, tmotorTetrix, openLoop, reversed, driveLeft, encoder)
#pragma config(Motor, mtr_S1_C1_2, motorright, tmotorTetrix, openLoop, driveRight, encoder)
#pragma config(Motor, mtr_S1_C2_1, upperlift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_2, sweeping, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_1, lowerlift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_2, arm, tmotorTetrix, openLoop, encoder)
#pragma config(Servo, srvo_S2_C1_1, pullarm, tServoStandard)
#pragma config(Servo, srvo_S2_C1_2, cylinder, tServoStandard)
#pragma config(Servo, srvo_S2_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S2_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S2_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S2_C1_6, servo6, tServoNone)
#include "JoystickDriver.c"
task main()
{
/* Int 'threshold' will allow us to ignore low */
long RightDrive = joystick.joy1_y2;
long LeftDrive = joystick.joy1_y1;
int armlowpos = joy1Btn(1);
int armhighpos = joy1Btn(3);
int armspinup = joy1Btn(2);
int armspindown = joy1Btn(0);
int lowerliftup = joy1Btn(5);
int lowerliftdown = joy1Btn(7);
int upperliftup = joy1Btn(6);
int upperliftdown = joy1Btn(4); /* readings that keep our robot in perpetual motion. */
while(true) // Infinite loop:
{
getJoystickSettings(joystick);
if(joystick.joy1_y2 > 25 || joystick.joy1_y2 < -25)
{
motor[motorright] = joystick.joy1_y2 / 1.5;
}
if(joystick.joy1_y1 > 25 || joystick.joy1_y1 < -25)
{
motor[motorleft] = joystick.joy1_y1 / 1.5;
}
if((joystick.joy1_y2 < 25) && (joystick.joy1_y2 > -25))
{
motor[motorright] = 0;
}
if((joystick.joy1_y1 < 25) && (joystick.joy1_y1 > -25))
{
motor[motorleft] = 0;
}
if(joy1Btn(5) == 1)
{
motor[lowerlift] = 100;
}
if(joy1Btn(7) == 1)
{
motor[lowerlift] = -30;
}
if(upperliftup == 1)
{
motor[upperlift] = 100;
}
if(upperliftdown == 1)
{
motor[upperlift] = -30;
}
if(armhighpos == 1)
{
nMotorEncoder[arm] = 0;
while (nMotorEncoder[arm] < 1440)
{
motor[arm] = 15;
}
motor[arm] = 0;
}
if(armlowpos == 1)
{
nMotorEncoder[arm] = 0;
while (nMotorEncoder[arm] < 1000)
{
motor[arm] = 15;
}
motor[arm] = 0;
}
if(armspinup == 1)
{
motor[arm] = 15;
}
if(armspindown == 1)
{
motor[arm] = -10;
if(joystick.joy1_TopHat == 0)//cylinder
{
servo[cylinder] = 225;
}
if(joystick.joy1_TopHat == 6)//pull
{
servo[pullarm] = 80;
}
if(joystick.joy1_TopHat == -1)//return
{
servo[cylinder] = 50;
servo[pullarm] = 0;
}
if(joystick.joy1_TopHat == 4)//spin
{
motor[sweeping] = 100; // Lower Servo 1 to position 20.
}
}
}
}
But even my robot program was a failure of the day, but I felt so good to complete the first assignment. I remember the point I have the program ran 100% correct, I jumped up from the chair, at that point, I have to event a new vocabulary to describe how exciting I was. The point that I complete the code, I suddenly feel like the code just become to a Christmas song, It looks so rhythmic at that point.
#pragma config(Hubs, S1, HTMotor, HTMotor, HTMotor, none)
#pragma config(Hubs, S2, HTServo, none, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorleft, tmotorTetrix, openLoop, reversed, driveLeft, encoder)
#pragma config(Motor, mtr_S1_C1_2, motorright, tmotorTetrix, openLoop, driveRight, encoder)
#pragma config(Motor, mtr_S1_C2_1, upperlift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C2_2, sweeping, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_1, lowerlift, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_2, arm, tmotorTetrix, openLoop, encoder)
#pragma config(Servo, srvo_S2_C1_1, pullarm, tServoStandard)
#pragma config(Servo, srvo_S2_C1_2, cylinder, tServoStandard)
#pragma config(Servo, srvo_S2_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S2_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S2_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S2_C1_6, servo6, tServoNone)
#include "JoystickDriver.c"
task main()
{
/* Int 'threshold' will allow us to ignore low */
long RightDrive = joystick.joy1_y2;
long LeftDrive = joystick.joy1_y1;
int armlowpos = joy1Btn(1);
int armhighpos = joy1Btn(3);
int armspinup = joy1Btn(2);
int armspindown = joy1Btn(0);
int lowerliftup = joy1Btn(5);
int lowerliftdown = joy1Btn(7);
int upperliftup = joy1Btn(6);
int upperliftdown = joy1Btn(4); /* readings that keep our robot in perpetual motion. */
while(true) // Infinite loop:
{
getJoystickSettings(joystick);
if(joystick.joy1_y2 > 25 || joystick.joy1_y2 < -25)
{
motor[motorright] = joystick.joy1_y2 / 1.5;
}
if(joystick.joy1_y1 > 25 || joystick.joy1_y1 < -25)
{
motor[motorleft] = joystick.joy1_y1 / 1.5;
}
if((joystick.joy1_y2 < 25) && (joystick.joy1_y2 > -25))
{
motor[motorright] = 0;
}
if((joystick.joy1_y1 < 25) && (joystick.joy1_y1 > -25))
{
motor[motorleft] = 0;
}
if(joy1Btn(5) == 1)
{
motor[lowerlift] = 100;
}
if(joy1Btn(7) == 1)
{
motor[lowerlift] = -30;
}
if(upperliftup == 1)
{
motor[upperlift] = 100;
}
if(upperliftdown == 1)
{
motor[upperlift] = -30;
}
if(armhighpos == 1)
{
nMotorEncoder[arm] = 0;
while (nMotorEncoder[arm] < 1440)
{
motor[arm] = 15;
}
motor[arm] = 0;
}
if(armlowpos == 1)
{
nMotorEncoder[arm] = 0;
while (nMotorEncoder[arm] < 1000)
{
motor[arm] = 15;
}
motor[arm] = 0;
}
if(armspinup == 1)
{
motor[arm] = 15;
}
if(armspindown == 1)
{
motor[arm] = -10;
if(joystick.joy1_TopHat == 0)//cylinder
{
servo[cylinder] = 225;
}
if(joystick.joy1_TopHat == 6)//pull
{
servo[pullarm] = 80;
}
if(joystick.joy1_TopHat == -1)//return
{
servo[cylinder] = 50;
servo[pullarm] = 0;
}
if(joystick.joy1_TopHat == 4)//spin
{
motor[sweeping] = 100; // Lower Servo 1 to position 20.
}
}
}
}
But even my robot program was a failure of the day, but I felt so good to complete the first assignment. I remember the point I have the program ran 100% correct, I jumped up from the chair, at that point, I have to event a new vocabulary to describe how exciting I was. The point that I complete the code, I suddenly feel like the code just become to a Christmas song, It looks so rhythmic at that point.