Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added px4fmu_sim branch for software in the loop (SITL) development #44

Closed
wants to merge 5 commits into from

Conversation

jgoppert
Copy link
Member

@jgoppert jgoppert commented Nov 4, 2012

I have created a new config under nuttx/config/px4fmu_sim. This builds the nsh console for px4 using the standard linux gcc toolchain. It then creates a virtual romfs and runs the px4 startup script. I wanted to get some feedback from the other developers before going any further. So please let me know what you guys think.

My main question is where should the SITL drivers go. I see that recently all of the code was moved out of nuttx/configs/px4fmu/src to apps/drivers/stm32. Should I create a folder in apps/drivers/sitl? It seems like the nuttx way would be to keep it under configs/px4fmu_sim/src but I can see how that is cumbersome.

Also, if anyone else has interest in helping to develop the SITL drivers, help would be appreciated. Luckily the default nuttx sim arch has a lot of the work done already.

@jgoppert
Copy link
Member Author

jgoppert commented Nov 4, 2012

Here is the current status of the sitl. I have a few more apps turned on, namely: systemlib, systemlib/mixer, systemcmds/mixer:

~/git/px4/src/Firmware$ ./Images/px4fmu_sim.exe 
NuttShell (NSH)
tone_alarm [2:100]
[init] looking for microSD... 
nsh: mount: mount failed: 2
[init] no microSD card found 
[init] script /fs/microsd/etc/rc not present 
nsh: sercon: command not found
[init] No USB connected 
[init] detecting attached hardware... 
nsh: boardinfo: command not found
[init] PX4IOAR not detected 
nsh: boardinfo: command not found
[init] PX4IO not detected 
[init] no expansion board detected 
[init] reading /etc/init.d/rc.standalone 
[init] doing standalone PX4FMU startup... 
nsh: uorb: command not found
nsh> 

@px4dev
Copy link
Contributor

px4dev commented Nov 5, 2012

On Nov 3, 2012, at 10:25 PM, James Goppert wrote:

I have created a new config under nuttx/config/px4fmu_sim. This builds the nsh console for px4 using the standard linux gcc toolchain. It then creates a virtual romfs and runs the px4 startup script.

When you say "builds the nsh console for px4", what do you mean?

From looking at your tree, it looks like you've added a new architecture called "sim" which looks like it serves the same basic purpose as the NuttX RGMP config, i.e. you're building a Linux app that behaves like the PX4 firmware.

I am thinking that the board specific code under app/drives/stm32 etc. should be moved to nuttx/config/px4fmu/src.

No; it just moved out of there. We want as little code as possible in the NuttX tree proper, as maintaining it is an enormous PITA.
This would allow the sitl to use the headers in drivers/drive_tone_alarm.h etc as interfaces for replacement driver implementations for the SITL setup. The SITL could then put its implementations in nuttx/config/px4fmu_sim/src.

Why wouldn't you put the SITL architecture's drivers in drivers/sim/* ?

= Mike

I wanted to get some feedback from the other developers before going any further. So please let me know what you guys think.

You can merge this Pull Request by running:

git pull https://github.com/jgoppert/Firmware px4fmu_sim
Or view, comment on, or merge it at:

#44

Commit Summary

Added px4fmu_sim config.
File Changes

M .gitignore (1)
M Makefile (27)
M ROMFS/Makefile (9)
A nuttx/arch/sim/Kconfig (103)
A nuttx/arch/sim/include/arch.h (80)
A nuttx/arch/sim/include/board (1)
A nuttx/arch/sim/include/irq.h (106)
A nuttx/arch/sim/include/limits.h (86)
A nuttx/arch/sim/include/syscall.h (82)
A nuttx/arch/sim/include/types.h (96)
A nuttx/arch/sim/src/GNU/Linux-names.dat (36)
A nuttx/arch/sim/src/Makefile (230)
A nuttx/arch/sim/src/board (1)
A nuttx/arch/sim/src/nuttx-names.dat (36)
A nuttx/arch/sim/src/up_allocateheap.c (85)
A nuttx/arch/sim/src/up_blockdevice.c (88)
A nuttx/arch/sim/src/up_blocktask.c (160)
A nuttx/arch/sim/src/up_createstack.c (114)
A nuttx/arch/sim/src/up_devconsole.c (106)
A nuttx/arch/sim/src/up_deviceimage.c (356)
A nuttx/arch/sim/src/up_elf.c (139)
A nuttx/arch/sim/src/up_exit.c (110)
A nuttx/arch/sim/src/up_framebuffer.c (399)
A nuttx/arch/sim/src/up_head.c (91)
A nuttx/arch/sim/src/up_hostusleep.c (66)
A nuttx/arch/sim/src/up_idle.c (159)
A nuttx/arch/sim/src/up_initialize.c (124)
A nuttx/arch/sim/src/up_initialstate.c (84)
A nuttx/arch/sim/src/up_internal.h (234)
A nuttx/arch/sim/src/up_interruptcontext.c (76)
A nuttx/arch/sim/src/up_lcd.c (428)
A nuttx/arch/sim/src/up_netdev.c (76)
A nuttx/arch/sim/src/up_releasepending.c (119)
A nuttx/arch/sim/src/up_releasestack.c (82)
A nuttx/arch/sim/src/up_reprioritizertr.c (178)
A nuttx/arch/sim/src/up_romgetc.c (101)
A nuttx/arch/sim/src/up_schedulesigaction.c (111)
A nuttx/arch/sim/src/up_setjmp.S (142)
A nuttx/arch/sim/src/up_stdio.c (82)
A nuttx/arch/sim/src/up_tapdev.c (271)
A nuttx/arch/sim/src/up_touchscreen.c (811)
A nuttx/arch/sim/src/up_uipdriver.c (230)
A nuttx/arch/sim/src/up_unblocktask.c (148)
A nuttx/arch/sim/src/up_usestack.c (101)
A nuttx/arch/sim/src/up_wpcap.c (312)
A nuttx/arch/sim/src/up_x11eventloop.c (140)
A nuttx/arch/sim/src/up_x11framebuffer.c (477)
M nuttx/configs/Kconfig (13)
A nuttx/configs/px4fmu_sim/Kconfig (26)
A nuttx/configs/px4fmu_sim/README.txt (601)
A nuttx/configs/px4fmu_sim/common/Make.defs (111)
A nuttx/configs/px4fmu_sim/include/board.h (366)
A nuttx/configs/px4fmu_sim/nsh/Make.defs (3)
A nuttx/configs/px4fmu_sim/nsh/appconfig (113)
A nuttx/configs/px4fmu_sim/nsh/defconfig (276)
A nuttx/configs/px4fmu_sim/nsh/setenv.sh (67)
A nuttx/configs/px4fmu_sim/src/Makefile (86)
A nuttx/configs/px4fmu_sim/src/empty.c (4)
A nuttx/configs/px4io/Kconfig (26)
Patch Links

https://github.com/PX4/Firmware/pull/44.patch
https://github.com/PX4/Firmware/pull/44.diff

Reply to this email directly or view it on GitHub.

px4@purgatory.org

@jgoppert
Copy link
Member Author

jgoppert commented Nov 5, 2012

I'm using the default nuttx sim arch. The only thing that I had to modify is add a copy of the linux math.h that has the arm #define constants for M_PI_2_F etc. Because of this change I renamed the arch to arm_sim.

I am running the nsh config and turning on the other apps for px4 one at a time. Currently I am trying to turn on the uOrb app but running into some undefined references:

uORB.cpp:(.text+0x8de3): undefined reference to `hrt_absolute_time'

I will probably need some help to get all of the drivers online.

I have started putting the drivers in drivers/sitl, I think drivers/arm_sim might be a better choice so I'll change that.

@px4dev
Copy link
Contributor

px4dev commented Nov 5, 2012

On Nov 4, 2012, at 4:26 PM, James Goppert wrote:

I'm using the default nuttx sim arch. The only thing that I had to modify is add a copy of the linux math.h that has the arm #define constants for M_PI_2_F etc. Because of this change I renamed the arch to arm_sim.

I am running the nsh config and turning on the other apps for px4 one at a time. Currently I am trying to turn on the uOrb app but running into some undefined references:

uORB.cpp:(.text+0x8de3): undefined reference to `hrt_absolute_time'
You need a replacement for drivers/stm32/drv_hrt, with the API documented in drivers/drv_hrt.h
I have started putting the drivers in drivers/sitl, I think drivers/arm_sim might be a better choice so I'll change that.

It is a mistake to call it "arm_sim", as there is nothing ARM-y about it. The change you've made to the NuttX sim arch to add math.h doesn't justify forking it; just add it the same way we did to the armv7 arch.

= Mike

px4@purgatory.org

@jgoppert
Copy link
Member Author

jgoppert commented Nov 5, 2012

Yes, will be much better if we can keep the nuttx sim/arch clean. I'll look into what you did for armv7.

@jgoppert
Copy link
Member Author

jgoppert commented Nov 8, 2012

Currently most of sitl is working. I have yet to do the simulation interface. Right now I am struggling getting the param setup to work correctly. I think the errors are related to variables referenced by the ld script.

I am working on understanding the ld.script more. I got the memory section up with this:

MEMORY
{
    flash (rx)   : ORIGIN = 0x00000000, LENGTH = 10M
    sram (rwx)   : ORIGIN = 0x10000000, LENGTH = 10M
    ccsram (rwx) : ORIGIN = 0x20000000, LENGTH = 10M
}

It was running out of flash with the current build in sim so I just gave it plenty of space.

I'm not sure why the __param_start isn't working correctly

Starting program: ~/git/px4/src/Firmware/Images/px4fmu_sim.exe
nsh_romfsetc: Mounting ROMFS filesystem at target=/etc with source=/dev/ram1

NuttShell (NSH)
[init] looking for microSD... 
nsh: mount: mount failed: 2
[init] no microSD card found 
[init] script /fs/microsd/etc/rc not present 
nsh: sercon: command not found
[init] No USB connected 
[init] detecting attached hardware... 
nsh: boardinfo: command not found
[init] PX4IOAR not detected 
nsh: boardinfo: command not found
[init] PX4IO not detected 
[init] no expansion board detected 
[init] reading /etc/init.d/rc.standalone 
[init] doing standalone PX4FMU startup... 
[uorb] ready
[init] eeprom 
nsh: eeprom: command not found
nsh> commander start
commander start
commander: param base: 80f9490, limit 80f9494, start 34, end 658: Unknown error

Program received signal SIGSEGV, Segmentation fault.
0x0805ba3d in param_find (name=0x80db1fc "SYS_FAILSAVE_LL")
    at /home/jgoppert/git/px4/src/Firmware/apps/systemlib/param/param.c:208
208         if (!strcmp(param_info_base[param].name, name))
(gdb) backtrace
#0  0x0805ba3d in param_find (name=0x80db1fc "SYS_FAILSAVE_LL")
    at /home/jgoppert/git/px4/src/Firmware/apps/systemlib/param/param.c:208
#1  0x08099c1d in commander_thread_main (argc=1, argv=0x820080c)
    at /home/jgoppert/git/px4/src/Firmware/apps/commander/commander.c:1168
#2  0x0804a214 in task_start ()
    at /home/jgoppert/git/px4/src/Firmware/nuttx/sched/task_start.c:113
#3  0x00000000 in ?? ()
(gdb) 

@jgoppert
Copy link
Member Author

jgoppert commented Nov 9, 2012

It was the "ABSOLUTE(.)" within the param section of the linker script, had to be just ".". I'm guessing I might have to remove some more ABSOLUTE flags in other sections.

nsh> commander start
commander start
[commander] I am in command now!
[commander] new state: SYSTEM_STATE_PREFLIGHT
nsh> 

@LorenzMeier
Copy link
Member

What is the current state of this branch? Is there a plan for the uORB implementation?

@jgoppert
Copy link
Member Author

All of the apps are compiling. Right now I have host tcp hooked up to the fake serial device and am trying to figure out why packets aren't coming to the host as expected. There is an empty sensor class that I will put another tcp connection in. Hrt code is there but not checked. Seems loops don't start till I cntrl-c the main process.

I haven't tried to debug uORB yet. I know that it is at least starting and runs without segfaults.

@jgoppert
Copy link
Member Author

Currently I'm trying to get my sleeping processes to wake. The docs say that the sim arch doesn't support a real timer or interrupts so I'm assuming this is related. I see however no reason why timer/ interrupt support can't be added. I sent Greg Nutt an email so maybe he can help.

@jgoppert
Copy link
Member Author

I haven't heard from Greg yet, but I think the issue here is that there is no real multi-threading. So since nsh is in the foreground waiting for command line input nothing happens. I fixed this temporarily by just not allowing user input on nsh. In the long term, maybe we can get true multi-threading running for sitl.

@jgoppert
Copy link
Member Author

Mavlink packets are coming in on tcp and it works with mavproxy. Now I just have to hook up the JSBSim tcp interface to the sensors app.

First I start the px4fmu simulation.

$ ./Images/px4fmu_sim.exe 
nsh_romfsetc: Mounting ROMFS filesystem at target=/etc with source=/dev/ram1
nsh_archinitialize: initializing sim arch
listening on tcp:5501

The simulation is now waiting for a tcp connection so we start mavproxy in another terminal.

$ mavproxy --master=tcp:localhost:5501
Logging to mav.tlog
MAV> online system 1 component 50
Mode(0x00000000)> Mode Mode(0x00000000)
APM: [commander] system is running
APM: [commander] Switched to STANDBY state
APM: [mavlink] No telemetry data for 1 s
Received 132 parameters
APM: [mavlink] No telemetry data for 1 s

Now the init procedure continues and starts the commander app.

NuttShell (NSH)
[init] looking for microSD... 
nsh: mount: mount failed: 2
[init] no microSD card found 
[init] script /fs/microsd/etc/rc not present 
nsh: sercon: command not found
[init] No USB connected 
[init] detecting attached hardware... 
nsh: boardinfo: command not found
[init] PX4IOAR not detected 
nsh: boardinfo: command not found
[init] PX4IO not detected 
[init] no expansion board detected 
[init] reading /etc/init.d/rc.standalone 
[init] doing standalone PX4FMU startup... 
[uorb] ready
mavlink: MAVLink v1.0 serial interface starting...
mavlink: DOWNLINK MODE
[mavlink] UART is /dev/ttyS1, baudrate is 57600
[commander] I am in command now!
[commander] new state: SYSTEM_STATE_PREFLIGHT
[init] startup done 
[init] startup done. 
[commander] new state: SYSTEM_STATE_STANDBY

@jgoppert
Copy link
Member Author

Right now I modified the rc.standalone script to call commander start etc, so this will have to be cleaned up before merging it.

@px4dev
Copy link
Contributor

px4dev commented Nov 26, 2012

That doesn't actually make any sense; if it's waiting for input it's not in the foreground, it's blocked.

On Nov 26, 2012, at 7:54 AM, James Goppert notifications@github.com wrote:

I haven't heard from Greg yet, but I think the issue here is that there is no real multi-threading. So since nsh is in the foreground waiting for command line input nothing happens. I fixed this temporarily by just not allowing user input on nsh. In the long term, maybe we can get true multi-threading running for sitl.


Reply to this email directly or view it on GitHub.

@jgoppert
Copy link
Member Author

It calls host fread which blocks until it receives input. But it can't execute any other process until fread returns. Greg said I would have to rewrite dev_console so it doesn't block.

@jgoppert
Copy link
Member Author

I setup the uORB test so that it checks across multiple processes. It appears that it is working on sitl. I'm not sure why the memory layout isn't affecting uORB when compiled on linux.

There is still an error between the ekf and sensor app communication with uORB on sitl that I am working out, but it must be unrelated.

@LorenzMeier
Copy link
Member

I fixed a bunch of HIL / mode enable issues in the fixedwing_outdoor branch. Can you update this branch, merge the two and report back the status? Please do not submit the merged version here, as we don't want to pull in all at once.

@px4dev
Copy link
Contributor

px4dev commented Jan 24, 2013

James; do you still want this?

@jgoppert
Copy link
Member Author

It needs a lot of work that I can't put into it right now. It would be a good starting point for anyone that does have time, but we can close the pull request. Maybe we should just add the branch to PX4 repo so people see that it does exist and they don't reinvent the wheel.

@px4dev
Copy link
Contributor

px4dev commented Jan 24, 2013

Ok; thanks for the update - I'll leave the pull request here for now and look for someone that's interested in working on it.

@LorenzMeier
Copy link
Member

Closing this, as we focus on ROS-based SITL now, which also allows a ROS native port.

@LorenzMeier LorenzMeier closed this Dec 2, 2014
msamogh pushed a commit to msamogh/Firmware that referenced this pull request Jun 7, 2019
PX4BuildBot added a commit that referenced this pull request Jan 7, 2020
NuttX:
 - https://github.com/PX4-NuttX/nuttx/tree/master
 - PX4/NuttX@973938d

Changes from PX4/NuttX (PX4/NuttX@9331fda) in current PX4/master (fc9df31)
PX4/NuttX@9331fda...973938d

973938dc1a (HEAD, origin/master) Merge branch 'master' of bitbucket.org:nuttx/nuttx
c5e25dc259 Merge branch 'master' of github.com:apache/incubator-nuttx
9d5d60f Run all .c and .h files in last PR49 through nxstyle.
a8d63c0 various fixes (#49)
077ef70 cxd56xx improvements (#48)
c5090d3 Merge branch 'master' of github.com:apache/incubator-nuttx
1c53d2b Nxstyle checkpatch support (#47)
4ea49c5 Fix issues on fe310 including interrupt handling (#46)
926a41f bcm43xxx: correct typo error to fix build break in photon board (#45)
aad99a5 Fix typo in the file_read description (#44)

Apps:
 - https://github.com/PX4/NuttX-apps/tree/master
 - PX4/NuttX-apps@74ba8ff

Changes from PX4/NuttX-apps (PX4/NuttX-apps@91b6ad6) in current PX4/master (fc9df31)
PX4/NuttX-apps@91b6ad6...74ba8ff

74ba8ff2 (HEAD -> master, origin/master) Merge pull request #5 from xiaoxiang781216/fix-void-cast
f00b4e6f Merge pull request #4 from xiaoxiang781216/fix-suffix
85715845 Unify the void cast usage
6a65664c Application.mk remove _main suffix from REGLIST
73e1696e Merge pull request #3 from xiaoxiang781216/builtin
7a645baa Add .updated target to handle the no builtin app case correctly
8c8c4813 fix builtin_list.c:58:10: fatal error: builtin_proto.h: No such file or directory (#2)
64bc8f5b Run all .c and .h files modified in last PR through nxstyle.
49c99750 Wapi simplify (#1)
0536c5b5 apps/nshlib/nsh_parse.c:  Correct an error found in build testing.  Commit 2a462c78aa5f4ea6dc374eedd86bc85f9f79a0c4 was insufficient.  It was a mistake to revert Xiang's change of commit 9defae8af641752506d92b72ea68c8f94d24d580.  But we are on a different vector now.
FlorianPix added a commit to mohndrilling/PX4-Autopilot that referenced this pull request Aug 15, 2022
FlorianPix added a commit to mohndrilling/PX4-Autopilot that referenced this pull request Aug 15, 2022
dirksavage88 pushed a commit to dirksavage88/Firmware that referenced this pull request Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants