C语言VEX编程示范,VEX编程 ROBOT C 主程序万向轮.c

这篇博客展示了如何使用C语言进行VEX机器人编程,主要内容包括配置传感器、马达控制以及一些关键参数设置,如极限位置和力度。在自动和用户控制模式下,机器人通过读取传感器数据来执行不同任务,如移动、抓取等。

#pragma config(Sensor, in2,  Gyro,  sensorGyro)

#pragma config(Sensor, in3,  LiftPot,  sensorPotentiometer)

#pragma config(Sensor, in7,  poten,  sensorPotentiometer)

#pragma config(Sensor, in8,  poten2,  sensorPotentiometer)

#pragma config(Sensor, dgtl1,  TouchSensor,

sensorTouch)

#pragma config(Sensor, dgtl2,  Claw_Encode,

sensorNone)

#pragma config(Sensor, dgtl5,

TouchSensor_Auto, sensorTouch)

#pragma config(Sensor, dgtl6,  Jumper_1,

sensorDigitalIn)

#pragma config(Sensor, dgtl7,  Jumper_2,

sensorDigitalIn)

#pragma config(Sensor, dgtl8,  Jumper_side,

sensorDigitalIn)

#pragma config(Sensor, dgtl9,  Base_Encode,

sensorQuadEncoder)

#pragma config(Sensor, dgtl11, Encode_1,  sensorQuadEncoder)

#pragma config(Motor,  port1,

intake_1,  tmotorVex393_HBridge,

openLoop, reversed)

#pragma config(Motor,  port2,

LeftRun_1,  tmotorVex393HighSpeed_MC29, openLoop,

reversed)

#pragma config(Motor,  port3,

LeftRun_2,  tmotorVex393HighSpeed_MC29, openLoop)

#pragma config(Motor,  port4,

ThrowTool2,

tmotorVex393HighSpeed_MC29,

openLoop, reversed)

#pragma config(Motor,  port5,

UpDown_1,  tmotorVex393_MC29, openLoop,

reversed)

#pragma config(Motor,  port6,

UpDown_2,  tmotorVex393_MC29,

openLoop)

#pragma config(Motor,  port7,

ThrowTool,  tmotorVex393HighSpeed_MC29, openLoop)

#pragma config(Motor,  port8,

RightRun_1,

tmotorVex393TurboSpeed_MC29,

openLoop)

#pragma config(Motor,  port9,

RightRun_2,

tmotorVex393HighSpeed_MC29,

openLoop, reversed)

#pragma config(Motor,  port10,

intake_2,  tmotorVex393_HBridge,

openLoop, reversed)

//

#pragma platform(VEX)

//Competition Control and Duration Settings

#pragma competitionControl(Competition)

#include "Vex_Competition_Includes.c"  //Main competition background code...do not modify!

#pragma autonomousDuration(20)

#pragma userControlDuration(120)

/////////////////////////////////////////////////////////////////////////////////////////////

int lock=2450;//tai shen zui gao jiao du

int out=1550;//tai shen zhong jian zhi

//int wavein=2700;//bai dong jin lai

//int waveout=1900;//bai dong chu qu

int Btm=1440;//tai shen zui di zhi

//int power=15;

int JoyCtrl=3;//3hao wei cfr yaokong fangshi

int CloseHold=2100;//1000+800

int BasePower=127;

int LiftPower=127;

int ThrowingPower=127;

int ThrowingPower2=127;

int ControlMod=0;

int Fantai=0;

////////////////////////////////////////////////////////////////////////////////////////////

int gro=76;

int Flager=0;

int Flager1=1;

int mode=0;

int side;

int key_value=0;

int Flager3=0;

int Flager4=0;

//int now=SensorValue[Gyro];

//different robot_move mode

#include "void.h"

#include "joystick.h"

#include "mainauto.h"

/////////////////////////////////////////////////////////////////////////////////////////

//

//  Pre-Autonomous Functions

//

// You may want to perform some actions before the competition

starts. Do them in the

// following function.

//

/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()

{

SensorType[in1] = sensorNone;

wait1Msec(100);

SensorType[in1] = sensorGyro;

wait1Msec(100);

// now block - use our own comp control

bStopTasksBetweenModes = true;

}

//////////////////////////////////////

void key_test ()

{

if (SensorValue(TouchSensor_Auto) ==

1&&(key_value==0))

{

AutoPro();

key_value=1;

}

}

/////////////////////////////////////////////////////////////////////////////////////////

//

//  Autonomous Task

//

// This task is used to control your robot during the

autonomous phase of a VEX Competition.

// You must modify the code to add your own robot specific

commands here.

//

/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()

{

AutoPro();

}

///////////////////////s//////////////////////////////////////////////////////////////////

//

//  User Control Task

//

// This task is used to control your robot during the user

control phase of a VEX Competition.

// You must modify the code to add your own robot specific

commands here.

//

////////////////////////////////

/////////////////////////////////////////////////////////

task usercontrol()

{

#include "userctrl.h"

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值