搜索
bottom↓
回复: 2

求高手详细解读程序,小弟感激不尽,不知道为什么这个是死循环!

[复制链接]

出0入0汤圆

发表于 2011-5-7 09:47:43 | 显示全部楼层 |阅读模式
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <linux/types.h>
#include <linux/fb.h>
#include <stdio.h>
#include <sys/wait.h>
#include <pthread.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <time.h>
#include <termios.h>                             
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>

int fd_track;
int fd_look;


//=======================PWM结构体================================
typedef struct PwmModel {
        int speed_L;  // LEFT speed
        int speed_R;                                                       
        char dir_L;       //1: resver   0: forward     
        char dir_R;
        //int  pwm_fd;
} PWMMODEL;
PWMMODEL motor={0,0,0,0};

//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

//-----------------------------PWM driver motor------------------------------------
/*========================================================
设置电机速度-249~249,正数表示前进,负数表示后退
=========================================================*/

void setSpeed(int onL,int onR)
{
        motor.speed_R=onL;
        motor.speed_L=onR;
        unsigned char pwm_cmd[4];
        if(motor.speed_R>=0){
                motor.dir_R=0;         
                motor.speed_R = motor.speed_R>249?249:motor.speed_R;
        }else{
                motor.dir_R=1;
                motor.speed_R=250-(-motor.speed_R);
                motor.speed_R = motor.speed_R>249?249:motor.speed_R;
        }
       
        if(motor.speed_L>=0){
                motor.dir_L=0;
                motor.speed_L = motor.speed_L>249?249:motor.speed_L;
        }else{
                motor.dir_L=1;
                motor.speed_L=250-(-motor.speed_L);
                motor.speed_L = motor.speed_L>249?249:motor.speed_L;
        }
       
        pwm_cmd[0]=motor.speed_R;
        pwm_cmd[1]=motor.speed_L;
        pwm_cmd[2]=motor.dir_R;
        pwm_cmd[3]=motor.dir_L;
        ioctl(fd_track,sizeof(pwm_cmd),pwm_cmd);

}

int main()
{


   printf("\n-----This is a test about MoonCar! ------\n\n");
  
   
/**********打开探月车控制驱动****************/
  if((fd_track=open("/dev/Car_Control",O_RDWR))<0)
    {
        printf("no open device");  
  }else{
                printf("Car_Control loaded!\n");
        }
       
        printf("Mooncar is running!\n");
       

        setSpeed(200,200);
        sleep(3);
        setSpeed(-150,150);
        sleep(3);
        setSpeed(150,-150);
        sleep(3);
        setSpeed(-200,-200);
        sleep(3);
        setSpeed(0,0);
        sleep(3);
        setSpeed(200,100);
        sleep(3);
        setSpeed(-200,-100);
        sleep(3);
        setSpeed(100,200);
        sleep(3);
        setSpeed(-100,-200);
        sleep(3);
                             }       
        }     
       

        close(fd_track);

  return 0;
}

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

发表于 2011-5-7 12:04:20 | 显示全部楼层
哪里

出0入0汤圆

发表于 2011-8-30 10:09:57 | 显示全部楼层
楼主:什么问题?描述清楚啊!莫名其妙,谁能帮你啊
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-15 10:07

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表