วันพุธที่ 3 ตุลาคม พ.ศ. 2555

เขียนโปรแกรม ?

ก็พึ่งรู้กับตัวเองว่านี้ว่าทำไมเวลาพัฒนาซอฟแวร์,ฮาร์ดแวร์ หรือ อะไรสักอย่างถึงทำกันหลายคน
ต้องแบ่งงานกันทำ จะ windows หรือ iphone สักรุ่น game สักเกม หรืออะไรสักอย่างมีทีมพัฒนามากมาย
วันก่อนก็กดลบจากข้างนอกไม่ได้เข้ามาดูพอวันนี้ลบไฟล์ผิดเข้ามาดู โอ้ 268 ครั้งนี้นั้งเขียนมา มันเหมือนเป็นเรื่องที่ไม่น่าเกิดขึ้นเลยแต่เกินขึ้นไปแล้ว ยังงงอยู่เลย


#pragma config(Sensor, S1, Motor1Senserspeed, sensorCOLORFULL)#pragma config(Sensor, S2, RLight, sensorLightActive)#pragma config(Sensor, S3, LLight, sensorLightActive)#pragma config(Motor, motorA, ACatch, tmotorNXT, PIDControl, encoder)#pragma config(Motor, motorB, RWheel, tmotorNXT, PIDControl, encoder)#pragma config(Motor, motorC, LWheel, tmotorNXT, PIDControl, encoder)//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*////#define USE_LineLeader#define LineLeaderAddr 0x02#define LL_READ_STEERING 0x42#define SensorPort S1#define LLightSensor_Threshold 60#define RLightSensor_Threshold 60#define LineLeader_Threshold 45#define MotorTurnSpeedTrack 15#define MotorTurnSpeed 25#define MotorDriveSpeed 30#define Motor1Senserspeed 25#define DegreeOfTurnLeft90 255#define DegreeOfTurnRight90 255#define DisplayTiming 0#define StopTiming 50#define LineCrossTiming 120#define SEN_ALL (SensorValue(LLight)<RLightSensor_Threshold &&SensorValue(RLight)<RLightSensor_Threshold )#define SEN_RIGHT (SensorValue(RLight)<RLightSensor_Threshold )#define SEN_LEFT (SensorValue(LLight)<RLightSensor_Threshold )#define SEN_FD (SensorValue(LLight)>RLightSensor_Threshold &&SensorValue(RLight)>RLightSensor_Threshold )#define SEN_BLACK (sensorValue(S1)==BLACKCOLOR)#define _NOTHING 0#define _AWAY 1#define _RIGHT 2#define _LEFT 3typedef byte byte_array[8];void rekeep(int n){nMotorEncoder(ACatch) = 0;while(nMotorEncoder(ACatch) < n){motor[ACatch] = 10;}motor[ACatch] = 0;}void keep(int n){nMotorEncoder(ACatch) = 0;while(nMotorEncoder(ACatch) > -n){motor[ACatch] = -100;}motor[ACatch] = 0;}//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MoveMent Function vvoid GoStraight(){motor[LWheel] = MotorDriveSpeed;motor[RWheel] = MotorDriveSpeed;wait1Msec(1);}void move_fd(int t){motor[LWheel] = MotorDriveSpeed;motor[RWheel] = MotorDriveSpeed;wait1Msec(t);}void move_bk(int t){motor[LWheel] = -MotorDriveSpeed;motor[RWheel] = -MotorDriveSpeed;wait1Msec(t);}void move_left(int t){motor[LWheel] = -MotorTurnSpeedTrack;motor[RWheel] = MotorDriveSpeed;wait1Msec(t);}void move_right(int t){motor[LWheel] = MotorDriveSpeed;motor[RWheel] = -MotorTurnSpeedTrack;wait1Msec(t);}void MotorStop(){motor[LWheel] = 0;motor[RWheel] = 0;wait1Msec(StopTiming);}void ao(int t){motor[LWheel] = 0;motor[RWheel] = 0;wait1Msec(t);}void LineCross(){GoStraight();wait1Msec(LineCrossTiming);}void HalfTurnLeft(){motor[LWheel] = 0;motor[RWheel] = Motor1Senserspeed ;}void HalfTurnRight(){motor[LWheel] = Motor1Senserspeed ;motor[RWheel] = 0;}void TurnLeft(){motor[LWheel] = -MotorTurnSpeed;motor[RWheel] = MotorTurnSpeed;}void TurnRight(){motor[LWheel] = MotorTurnSpeed;motor[RWheel] = -MotorTurnSpeed;}void TurnLeft90(){nMotorEncoder(RWheel) = 0;while(nMotorEncoder(RWheel) < DegreeOfTurnLeft90)TurnLeft();MotorStop();}void TurnRight90(){nMotorEncoder(LWheel) = 0;while(nMotorEncoder(LWheel) < DegreeOfTurnRight90)TurnRight();MotorStop();}void changedirect(int direct){if(direct==1){LineCross();move_fd(100);}if(direct==2){LineCross();TurnRight90();}if(direct==3){LineCross();TurnLeft90();}}void move_fd_encode(int n){nMotorEncoder(RWheel) = 0;while(nMotorEncoder(RWheel) < n){motor[RWheel] = 40;motor[LWheel] = 40;}motor[RWheel] = 0;motor[LWheel] = 0;}void move_bk_encode(int n){nMotorEncoder(RWheel) = 0;while(nMotorEncoder(RWheel) > -n){motor[RWheel] = -40;motor[LWheel] = -40;}motor[RWheel] = 0;motor[LWheel] = 0;motor[RWheel] = 0;motor[LWheel] = 0;}//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!MoveMent Function ^// ---------------- Trackline funtion---------------////!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!LineLeader Function vbool LL_ReadRaw_Calibrated (tSensors port, byte i2cAddr, byte_array &returnValue){byte msg[5];byte replyMsg[8];msg[0] = 2;msg[1] = i2cAddr;msg[2] = 0x49;while (nI2CStatus[port] == STAT_COMM_PENDING){// Wait for I2C bus to be ready}// when the I2C bus is ready, send the message you builtwhile (nI2CStatus[port] == STAT_COMM_PENDING){// Wait for I2C bus to be ready}// read back the response from I2Cmemcpy(returnValue, replyMsg, 8);return true;}byte LL_Read (tSensors port, byte i2cAddr, byte reg_to_read){byte msg[5];byte replyMsg[2];msg[0] = 2;msg[1] = i2cAddr;msg[2] = reg_to_read;while (nI2CStatus[port] == STAT_COMM_PENDING){// Wait for I2C bus to be ready}// when the I2C bus is ready, send the message you builtwhile (nI2CStatus[port] == STAT_COMM_PENDING){// Wait for I2C bus to be ready}// read back the response from I2Creturn (replyMsg[0]);}void LineLead(int direct){signed byte steering;while (!SEN_ALL) {steering = LL_Read(SensorPort, LineLeaderAddr, LL_READ_STEERING);steering = (signed int)( 0xff & steering);nxtDisplayTextLine (5,"steering: %d", steering);if(steering>=(-12)&&steering<=12){GoStraight();}else if(steering<=(-12)){move_right(1);}else if(steering>=12){move_left(1);}}changedirect(direct);}void LineLead_check(int direct){signed byte steering;while (!SEN_ALL) {steering = LL_Read(SensorPort, LineLeaderAddr, LL_READ_STEERING);steering = (signed int)( 0xff & steering);nxtDisplayTextLine (5,"steering: %d", steering);if(steering>=(-4)&&steering<=4){motor[RWheel] = 10;motor[LWheel] = 10;}else if(steering<=(-4)){motor[RWheel] = -30;motor[LWheel] = 30;}else if(steering>=4){motor[RWheel] = 30;motor[LWheel] = -30;}}changedirect(direct);}void LineLead_LEFT(int direct){signed byte steering;while (!SEN_LEFT) {steering = LL_Read(SensorPort, LineLeaderAddr, LL_READ_STEERING);steering = (signed int)( 0xff & steering);nxtDisplayTextLine (5,"steering: %d", steering);if(steering>=(-12)&&steering<=12){GoStraight();}else if(steering<=(-12)){move_right(1);}else if(steering>=12){move_left(1);}}changedirect(direct);}void LineLead_RIGHT(int direct){signed byte steering;while (!SEN_RIGHT) {steering = LL_Read(SensorPort, LineLeaderAddr, LL_READ_STEERING);steering = (signed int)( 0xff & steering);nxtDisplayTextLine (5,"steering: %d", steering);if(steering>=(-12)&&steering<=12){GoStraight();}else if(steering<=(-12)){move_right(1);}else if(steering>=12){move_left(1);}}changedirect(direct);}void tracline_senall(int direct){while(!SEN_ALL){if(SEN_FD) move_fd(1);else if(SEN_LEFT) move_left(1);else if(SEN_RIGHT) move_right(1);}changedirect(direct);}void tracline_left(int direct){while(!SEN_LEFT){if(SEN_RIGHT) HalfTurnRight();else HalfTurnLeft();}changedirect(direct);}void tracline_right(int direct){while(!SEN_RIGHT){if(SEN_LEFT) HalfTurnLeft();else HalfTurnRight();}changedirect(direct);}void tracline_right2(int direct){move_bk_encode(100);while(!SEN_RIGHT){if(SEN_LEFT) HalfTurnLeft();else HalfTurnRight();}changedirect(direct);}//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!LineLeader Function ^void motorR_fd(int n){nMotorEncoder(RWheel) = 0;while(nMotorEncoder(RWheel) < n){motor[RWheel] = 40;motor[LWheel] = 0;}motor[RWheel] = 0;motor[LWheel] = 0;}void motorL_fd(int n){nMotorEncoder(LWheel) = 0;while(nMotorEncoder(LWheel) < n){motor[LWheel] = 40;motor[RWheel] = 0;}motor[RWheel] = 0;motor[LWheel] = 0;}void move_fd2(int t){motor[LWheel] = 70;motor[RWheel] = 70;wait1Msec(t);}void tracline_senall2(int direct){while(!SEN_ALL){if(SEN_FD) move_fd2(1);else if(SEN_LEFT) move_left(1);else if(SEN_RIGHT) move_right(1);}changedirect(direct);}void save_w(int vmfe){TurnRight90();TurnRight90();  // uTurntracline_senall(_RIGHT);move_fd_encode(100);motorL_fd(50);MotorStop();tracline_senall(_AWAY);MotorStop();tracline_senall(_NOTHING);MotorStop();tracline_senall(_NOTHING);MotorStop();move_fd_encode(vmfe);rekeep(290);move_bk_encode(300+vmfe);TurnLeft90();move_fd_encode(300);tracline_senall(_AWAY);TurnLeft90();motorL_fd(50);move_fd_encode(300);}void save_b(int vmfe){TurnLeft90();TurnLeft90();  // uTurntracline_senall(_LEFT);move_fd_encode(100);motorR_fd(30);MotorStop();tracline_senall(_AWAY);MotorStop();tracline_senall(_NOTHING);MotorStop();tracline_senall(_NOTHING);MotorStop();move_fd_encode(vmfe);rekeep(290);move_bk_encode(300+vmfe);TurnRight90();move_fd_encode(300);tracline_senall(_AWAY);TurnRight90();motorL_fd(50);move_fd_encode(300);}void starx(){tracline_senall2(_AWAY);tracline_senall(_NOTHING);tracline_senall(_NOTHING);move_fd_encode(300);keep(230);wait10Msec(50);move_bk_encode(300);}// Catindy'sFunctiontask main(){int vx1=0;int vx2=0;int vxw=350;int vxb=350;move_fd_encode(300);tracline_senall(_AWAY);while(vx1<8){starx();if(SEN_BLACK){save_b(vxb);vxb=vxb-140;vx2=0;}else{save_w(vxw);vxw=vxw-150;vx2=1;}vx1++;}if(vx2==0){TurnRight90();TurnRight90();tracline_senall(_AWAY);tracline_senall(_NOTHING);move_fd_encode(300);MotorStop();}else{TurnLeft90();TurnLeft90();tracline_senall(_AWAY);tracline_senall(_NOTHING);move_fd_encode(300);MotorStop();}}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น