Nuttx下新建路径以及motors

前言

之前在nuttx下编写应用的时候,陷入了之前写单片机代码的误区,没有很好的讲逻辑层和驱动层的代码分割开来,
导致写出来的程序,可读性和可移植性太差,这次参考ardupilot的思路重新整理下实现的过程;

目标

实现一个电机接口库,具体目标如下:
1.这个库应该是建立在nuttx上;
2.利用os原有的PWM驱动以及IO驱动实现电机的控制接口;
3.抽象出电机模型(例如差速模型、姿态模型、自行车模型、单电机模型...);
4.文件目录层级:
	|—../app/libraries
					|—motor
							|—差速模型(*.c、.h、.....)
							|—自行车模型(*.c、.h、.....)
							|—.......
							|—单电机模型(*.c、.h、.....)
					|—InertialSensor
					....
					|—编译文件(makefile、Kconfig、make.dep、make.defs)

文件的大概目录就是这样,下面结合实际的例子来详细说明。

libraries

 libraries这个文件夹是新建的,就从这里开始吧~

然后编译器在编译的时候才找得到新建的源文件,从而编译;
首先在app下面按照上面的文件目录层级建立好所需要的源文件,接下怎么呢?
刚开始我蒙圈了,经验告诉我去看看readme,里面有如下描述:(我就只挑重点的来了)

Building NuttX with Board-Specific Pieces Outside the Source Tree
-----------------------------------------------------------------
   3) If you like the random collection of stuff in the apps/ directory
      but just want to expand the existing components with your own,
      external sub-directory then there is an easy way to that too:
      You just create a sympolic link in the apps/ directory that
      redirects to your application sub-directory.

      In order to be incorporated into the build, the directory that
      you link under the apps/ directory should contain (1) a Makefile
      that supports the clean and distclean targets (see other Makefiles
      for examples), and (2) a tiny Make.defs file that simply adds the
      custon build directories to the variable CONFIGURED_APPS like:

        CONFIGURED_APPS += my_directory1 my_directory2

      The apps/Makefile will always automatically check for the
      existence of subdirectories containing a Makefile and a Make.defs
      file.  The Makefile will be used only to support cleaning operatio
### 创建 HelloWorld 示例程序 要在 NuttX 操作系统中创建 HelloWorld 示例程序,需遵循特定的目录结构和配置流程。程序通常位于 `apps/examples/hello/hello_main.c` 文件内,在此文件中可以进行必要的修改并随后编译运行[^1]。 #### 准备工作环境 确保已正确安装并配置好 NuttX 开发环境,包括工具链和其他依赖项。这一步骤对于后续操作至关重要。 #### 编写 HelloWorld 程序 下面是一个简单的 HelloWorld C 语言源码实例: ```c #include <nuttx/config.h> #include <stdio.h> int hello_main(int argc, char *argv[]) { printf("Hello, NuttX!\n"); return 0; } ``` 这段代码实现了基本功能:当执行时会在控制台打印 "Hello, NuttX!" 字符串。 #### 修改 Makefile 和 Kconfig 文件 为了使新添加的应用成为构建过程的一部分,还需要编辑相应的 `Makefile` 及 `Kconfig` 文件来注册这个应用程序。具体路径通常是 `apps/examples/Makefile` 和同级目录下的 `Kconfig` 文件。 - **Makefile**: 添加如下内容以便于链接器能找到目标文件。 ```makefile ifeq ($(CONFIG_EXAMPLES_HELLO),y) SRCS += hello_main.c endif ``` - **Kconfig**: 插入以下片段用于提供菜单选项让用户选择是否启用该应用 ```kconfig config EXAMPLES_HELLO bool "Hello example" default y help This is the Hello world example application. ``` 完成上述更改之后保存所有改动过的文件,并返回到项目的根目录准备下一步动作。 #### 构建与部署 利用命令行工具进入 NuttX 工程顶层目录后输入相应指令来进行整个系统的重新编译以及烧录固件至开发板上测试效果。 ```bash cd path/to/nuttx/ ./tools/configure.sh YOUR_BOARD_NAME-YOUR_CONFIG_TYPE make clean && make -j$(nproc) ``` 最后通过连接终端模拟器查看输出结果验证 HelloWorld 是否成功显示出来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值