51uwb.cn

 找回密码
 立即注册
查看: 285|回复: 4
打印 上一主题 下一主题

bp30两个基站一个标签想要实现跟随小车,应该怎么修改源码?

[复制链接]

1

主题

4

帖子

15

积分

新手上路

Rank: 1

积分
15
跳转到指定楼层
楼主
发表于 2024-6-27 15:55:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问bp30的如何利用两个基站和一个标签实现跟随小车?应该在源码的哪里进行修改?
根据客服的这个FollowCar原理链接: https://pan.baidu.com/s/1ZNUvUGZXKbN-3SrIyuqOFA 提取码: wsts,我没有在源码中找到相应的位置
如果bp30也可以应用上面的这个修改的话,应该在源码哪里进行修改呢?
如果bp30不能直接用上面的这个,那么应该怎么更改源码才能实现两个基站一个标签的跟随小车呢?
麻烦您了。

回复

使用道具 举报

35

主题

1006

帖子

4321

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4321
沙发
发表于 2024-6-27 21:59:37 | 只看该作者
你看看这里,需要标签发送给基站的时候增加代码
  1. #define DISTANCE3 0.27

  2. //**************************************************************//
  3. //distance1 anthor0 <--> TAG  mm
  4. //distance2 anthor1 <--> TAG  mm
  5. //distance3 anthor2 <--> TAG  mm
  6. //**************************************************************//

  7. int framenum = 0 ;

  8. static void compute_angle_send_to_anthor0(int distance1, int distance2,int distance3)
  9. {

  10. #if 0 //compute angle for smartcar
  11.     float dis3_constans = DISTANCE3;
  12.     float cos = 0;
  13.     float angle = 0 ;
  14.     float dis1 = (float)distance1/1000; //m
  15.     float dis2 = (float)distance2/1000;  //m

  16.     if(dis1 + dis3_constans < dis2 || dis2+dis3_constans < dis1)
  17.     {
  18.     }
  19.     cos = (dis1*dis1 + dis3_constans* dis3_constans - dis2*dis2)/(2*dis1*dis3_constans);
  20.     angle  = acos(cos)*180/3.1415926;
  21.     printf("cos = %f, arccos = %f\r\n",cos,angle);
  22.     sprintf(dist_str, "angle: %3.2f m", angle);
  23.     OLED_ShowString(0, 6,"            ");
  24.     OLED_ShowString(0, 6,dist_str);

  25.     if(dis1 > 1)
  26.     {
  27.         if(angle > 110)
  28.         {
  29.             printf("turn right\r\n");
  30.             angle_msg[10] = 'R';
  31.         }
  32.         else if(angle < 75)
  33.         {
  34.             printf("turn left\r\n");
  35.             angle_msg[10] = 'L';
  36.         }
  37.         else
  38.         {
  39.             printf("forward\r\n");
  40.             angle_msg[10] = 'F';
  41.         }
  42.     }
  43.     else
  44.     {
  45.         printf("stay here\r\n");
  46.         angle_msg[10] = 'S';
  47.     }
  48.     angle_msg[LOCATION_FLAG_IDX] = 0;

  49. #else
  50.     //location
  51.     {
  52.         uint8 len = 0;
  53.         angle_msg[LOCATION_FLAG_IDX] = 1;

  54.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = 'm';
  55.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = 'r';

  56.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = 0x02;
  57.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = TAG_ID;//TAG ID

  58.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)(framenum&0xFF);
  59.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((framenum>>8)&0xFF);

  60.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10)&0xFF);
  61.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10 >>8)&0xFF);

  62.         angle_msg[LOCATION_INFO_START_IDX + (len++)] =  (uint8)((distance2/10)&0xFF);
  63.         angle_msg[LOCATION_INFO_START_IDX + (len++)] =  (uint8)((distance2/10 >>8)&0xFF);

  64.         angle_msg[LOCATION_INFO_START_IDX + (len++)] =  (uint8)((distance3/10)&0xFF);
  65.         angle_msg[LOCATION_INFO_START_IDX + (len++)] =  (uint8)((distance3/10 >>8)&0xFF);

  66.         if(ANCHOR_MAX_NUM > 3)
  67.         {
  68.             angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((Anthordistance[3]/10)&0xFF);
  69.             angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((Anthordistance[3]/10 >>8)&0xFF);
  70.         }
  71.         else
  72.         {
  73.             angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10)&0xFF);
  74.             angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10 >>8)&0xFF);
  75.         }

  76.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = '\n';
  77.         angle_msg[LOCATION_INFO_START_IDX + (len++)] = '\r';


  78.         angle_msg[LOCATION_INFO_LEN_IDX] = len;
  79.         //MAX LEN
  80.         if(LOCATION_INFO_START_IDX + len -2 >ANGLE_MSG_MAX_LEN)
  81.         {
  82.             while(1);
  83.         }
  84.         //USART_puts((char*)angle_msg,len);
  85.     }
  86. #endif
  87.     //only anthor0 recive angle message
  88.     //angle_msg[ALL_MSG_SN_IDX] = framenum;
  89.     angle_msg[ALL_MSG_TAG_IDX] = TAG_ID;

  90.     dwt_writetxdata(sizeof(angle_msg), angle_msg, 0);
  91.     dwt_writetxfctrl(sizeof(angle_msg), 0);

  92.     /* Start transmission, indicating that a response is expected so that reception is enabled automatically after the frame is sent and the delay
  93.      * set by dwt_setrxaftertxdelay() has elapsed. */
  94.     dwt_starttx(DWT_START_TX_IMMEDIATE );
  95.     while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
  96.     { };

  97.     framenum++;
  98. }
复制代码
回复

使用道具 举报

1

主题

4

帖子

15

积分

新手上路

Rank: 1

积分
15
板凳
 楼主| 发表于 2024-6-28 20:12:44 | 只看该作者
蓝点无限 发表于 2024-6-27 21:59
你看看这里,需要标签发送给基站的时候增加代码

不好意思,我是小白,请问您的意思是我找到标签发送给基站的那段代码,然后把你上面发的这段代码粘上去吗,我不太知道要把这个粘到哪里,您能告诉我一下吗
回复

使用道具 举报

1

主题

4

帖子

15

积分

新手上路

Rank: 1

积分
15
地板
 楼主| 发表于 2024-6-29 20:19:40 | 只看该作者
蓝点无限 发表于 2024-6-27 21:59
你看看这里,需要标签发送给基站的时候增加代码

你看一下我新回复的
回复

使用道具 举报

35

主题

1006

帖子

4321

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4321
5#
发表于 2024-6-29 20:53:15 | 只看该作者
dzq 发表于 2024-6-29 20:19
你看一下我新回复的

BP30 tx_main.c 中有类似逻辑,标签和三个基站测距完成后,汇总信息会发送给基站id 为0x0001 的基站,参考代码如下。

你需要做的就是把上面回答的逻辑代码实现到如下函数中,如果代码没有阅读,请先梳理代码逻辑。

  1. /**********************************END***********************************/
  2. /************************************************************************/

  3. //**************************************************************//
  4. //distance1 anthor0 <--> TAG  cm
  5. //distance2 anthor1 <--> TAG  cm
  6. //distance3 anthor2 <--> TAG  cm
  7. //将三个距离信息发送给基站1--> 0x0001
  8. //如果用其它无限模块通信,可以将这三个距离信息通过其它无线模块传输给电脑
  9. //**************************************************************//
  10. /*******************************************************************************
  11. * 函数名  : Send_Dis_To_Anthor1
  12. * 描述    : 标签将三个收到的三个距离信息打包发送到基站0(基站0的SHORT地址0x0001)
  13. * 输入    : 无
  14. * 输出    : 无
  15. * 返回值  : 无
  16. * 说明    : 1将距离信息发送到0x0001地址的基站
  17.                                                 2通过液晶显示-->只能显示三个距离,液晶每行一个距离
  18. *******************************************************************************/
  19. static void Send_Dis_To_Anthor1(void)
  20. {
复制代码



另外,基站1收到标签信息,之前默认定位,直接通过串口发送给电脑,修改逻辑后,需要修改成类似
  1.              if(rx_buffer[LOCATION_FLAG_IDX] == 1)//location infomartion
  2.                 {
  3.                     rx_buffer[ALL_MSG_TAG_IDX] = tag_index;
  4.                     USART_puts(&rx_buffer[LOCATION_INFO_START_IDX],rx_buffer[LOCATION_INFO_LEN_IDX]);
  5.                 }
  6.                 else //follow car
  7.                 {
  8.                     putchar(rx_buffer[10]);
  9.                 }
  10.             }
复制代码


因为BP30 和 BP50 代码不是一套,只是提供了逻辑实现,并非直接拷贝替换就能使用,还需要根据上面逻辑在做微调。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

bphero Inc.  

GMT+8, 2024-9-8 12:22 , Processed in 0.014974 second(s), 4 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】

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