前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >2018-11-17DobotDemoV2.0解析

2018-11-17DobotDemoV2.0解析

作者头像
用户1733354
发布2018-12-14 10:54:01
9560
发布2018-12-14 10:54:01
举报

DobotDemoV2.0下载地址

DobotDemoV2.0--》DobotDemoForArduino--》DobotDemo--》DobotDemo.ino

两个arduino的rx tx交叉连接,同时两个arduino通过usb连接在pc上,用pc向其中一个arduino发送一个数字(称此arduino为主机),主机将此数字通过tx串口发送给另一个arduino(称此arduono为从机),然后从机通过rx串口接收?

串口不够用可以考虑使用SoftwareSerial

一、连线

1、dobot连接电源

2、mega 2560板子upload程序DobotDemo.ino

3、dobo 的Rx连接mega 2560板子的Tx1,GND连接起来,(板子的Rx1可以不用和Dobot的Tx相连)打开dobot开关可以看到dobot动起来了。如果usb连着电脑mega板子上面的tx灯会亮,如果mega板子用电源供电,未用usb连着电脑tx灯不会亮

板子上Tx1连接Dobot Rx

板子上Tx1连接Dobot Rx,Rx1连接Dobot Tx

二、setup()

   1、 Serial.begin(115200);  Arduino菜鸟通俗版解读系列(4)串口通信---USART

   2、Serial1.begin(115200);

   3、 printf_begin();         在Arduino上使用printf格式化输出到串口

   4、FlexiTimer2::set(100,Serialread); FlexiTimer2.h 定时器 使用

          FlexiTimer2::start();      和delay(100)功能相同,但用delay时mcu会被占用,只能傻等在那儿,使用定时器中断可以在这100ms同时做其他的事情,隔100ms来执行一下Serialread函数。

         每隔100ms执行1次Serialread函数:读Serial1的数据病存入

         void Serialread(){

           while(Serial1.available()) { 

             uint8_t data = Serial1.read();      mega的Rx从dobot读到的数据

             if (RingBufferIsFull(&gSerialProtocolHandler.rxRawByteQueue) == false) {

                    RingBufferEnqueue(&gSerialProtocolHandler.rxRawByteQueue, &data);

        } }}

RingBuffer.h:RingBufferIsFull,RingBufferEnqueue

Protocol.h:gSerialProtocolHandler

ProtocolDef.h:rxRawByteQueue

执行loop期间隔100ms会去执行1次Serialread函数,所以以上这些参数的初始化都在loop的: 2、ProtocolInit()中

二、loop()

执行loop期间隔100ms会去执行1次Serialread函数

   1、InitRAM();     本程序中的函数,进行一些参数的初始化

   2、 ProtocolInit();   见Protocol.cpp

   3、设置dobot的运动参数

   command.cpp:几个Set...把gJOGJointParams存到Message对象的指令队列中

   然后通过message.cpp和doBot进行通信,控制doBot

   SetJOGJointParams(&gJOGJointParams, true, &gQueuedCmdIndex);          

   SetJOGCoordinateParams(&gJOGCoordinateParams, true, &gQueuedCmdIndex);  

   SetJOGCommonParams(&gJOGCommonParams, true, &gQueuedCmdIndex);

    printf("\r\n======Enter demo application======\r\n");

    SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);

    for(; ;)

    {

        static uint32_t timer = millis();

        static uint32_t count = 0;

        #ifdef JOG_STICK

        if(millis() - timer > 1000)

        {

            timer = millis();

            count++;

            switch(count){

                case 1:

                    gJOGCmd.cmd = AP_DOWN;

                    gJOGCmd.isJoint = JOINT_MODEL;

                    SetJOGCmd(&gJOGCmd, true, &gQueuedCmdIndex);

                    break;

                case 2:

                    gJOGCmd.cmd = IDEL;

                    gJOGCmd.isJoint = JOINT_MODEL;

                    SetJOGCmd(&gJOGCmd, true, &gQueuedCmdIndex);

                    break;

                case 3:

                    gJOGCmd.cmd = AN_DOWN;

                    gJOGCmd.isJoint = JOINT_MODEL;

                    SetJOGCmd(&gJOGCmd, true, &gQueuedCmdIndex);

                    break;

                case 4:

                    gJOGCmd.cmd = IDEL;

                    gJOGCmd.isJoint = JOINT_MODEL;

                    SetJOGCmd(&gJOGCmd, true, &gQueuedCmdIndex);

                    break;

                default:

                    count = 0;

                    break;

              }

        }

        #else

        if(millis() - timer > 3000)

        {

            timer = millis();

            count++;

            if(count & 0x01)

            {

                gPTPCmd.x += 100;

                SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);

            }

            else

            {

                gPTPCmd.x -= 100;

                SetPTPCmd(&gPTPCmd, true, &gQueuedCmdIndex);

            }

        }

        #endif

        ProtocolProcess();

    }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.11.18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档