View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
NXTway-GS (Self-Balancing Two-Wheeled Robot) Controller Design

4.9 | 16 ratings Rate this file 69 Downloads (last 30 days) File Size: 11.3 MB File ID: #19147 Version: 1.5
image thumbnail

NXTway-GS (Self-Balancing Two-Wheeled Robot) Controller Design



11 Mar 2008 (Updated )

NXTway-GS Model-Based Design based on Embedded Coder Robot NXT.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

NXTway-GS is a self-balancing two-wheeled robot built with LEGO Mindstorms NXT and a Hitechnic gyro sensor. This demo presents sample models and documents describe the following contents.

How to Build NXTway-GS
Mathematical Dynamics Model of NXTway-GS
Controller Design for Balance and Drive Control
NXTway-GS Model Illustration
Simulation and Experimental Results

You can simulate NXTway-GS model and generate controller program that can be executed on the NXT. You can watch the movies of NXTway-GS simulation and control experiment at the following URL.

This demo uses Embedded Coder Robot NXT Demo as MBD environment. You need to download it from the following URL before trying this demo.

LEGO(R) is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this demo. LEGO(R) and Mindstorms(R) are registered trademarks of The LEGO Group.


Embedded Coder Robot Nxt Demo, Nxt Scara (Two Link Planar Robot Arm) Controller Design, and Nxt Ballbot (Self Balancing Robot On A Ball) Controller Design inspired this file.

This file inspired Nx Tbike Gs (Self Balancing Bike Robot By Steer Into Fall), Vu Lego Real Time Target, Nxt Ltd: Line Tracking Dancing Robot Demo, Gyroboy Self Balancing Two Wheel Robot (Segway) Based On Lego Ev3, Nxt Scara (Two Link Planar Robot Arm) Controller Design, Nxt Ballbot (Self Balancing Robot On A Ball) Controller Design, and Embedded Coder Robot Nxt Demo.

Required Products Control System Toolbox
Fixed-Point Designer
Simulink Coder
Embedded Coder
Simulink Fixed Point
Simulink 3D Animation
MATLAB release MATLAB 7.5 (R2007b)
Other requirements nxtOSEK, Cygwin, GNU ARM
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (26)
11 Sep 2015 castle zhang


Comment only
15 Jun 2015 Marjan Sarafimov

Is it possible that i have not connected a NXTway-Gs with my PC yet, because i just wanted to make only a simulation on my PC..?

Unable to open model file 'nxtway_gs_controller.mdl'.

Comment only
22 May 2015 Shawn Tang

I have a problem in the two generalized
coordinates you choose.the first one is θ: Average angle of left and right wheel,why do you think it equals 1/2(θr+θl) ,the second one is φ: Body yaw angle,why do you think it equals R/W*(θr-θl).the two generalized coordinates has been puzzled me for days,and I am in deep affliction for it.would you please explain this two Eqs. of the generalized coordinates to me for the for the further?

23 Feb 2015 weichen li

Unable to load block diagram 'ecrobot_nxt_lib'


Comment only
13 Nov 2014 Nguyen

Nguyen (view profile)

Hello! thank you for your working.
I have some problems, it didnot work with me. I have a matlab R2013.
When I run the simulink file "nxtway_gs_vr.mdl", it has the error:

Error evaluating 'InitFcn' callback of Battery Voltage Interface block (mask) 'nxtway_gs_controller/Battery Voltage Interface'.
Caused by:
Undefined function or variable 'NXT.Signal'.

Anyone know how to fix it? please help me, thank you very much

14 Sep 2014 zhu qunchao

29 Mar 2013 dirawe

dirawe (view profile)

16 Aug 2011 cheung kwan

can anyone tell me what modification i have to make to use the Lego small wheels?

thank you

Comment only
11 Jun 2011 Deyan Dobromirov

22 May 2011 jasan

jasan (view profile)

phillip did you ever find out about the observer implementation?

Comment only
20 May 2011 jasan

jasan (view profile)

I tried simulating this controller in simulink but i get errors for stating (source function do not exist) such as sfun_bt_tx, sfun_bt_rx, sfun_soundtone, sfun_expfcncallsscheduler. This is weird beacuse with the download of ecrobotNXT in the environment directory these do exist in a C file and as .mexw32. Could the problem be that I'm running this on X64 bit windows 7? Any help will very very much appreciated

30 Sep 2010 Rajasekaran

12 May 2010 Juan Luna

Philipp, i have completed the controller becoming both dynamics into one, and close the loop control in the wheel dynamics, but i calculated the remain states from the on-board sensors. the controller can track lineal and angular velocities. but the idea of an observer was made by Takachi in his early nxtWAY in with use a ligth sensor to determinate the states (ecrobot exmples).

Comment only
04 May 2010 Nguyen Hieu

29 Apr 2010 Philipp B


has somebody implented an observer based strategy for the non measured states? Great work by the way, but from the view of modern control theory an observer based method would be even better.

Comment only
16 Mar 2010 Juan Luna

> Yorihisa Yamamoto

Hello, I first want to say that a person who designs a system so well, as seen in the archives of NXTway-GS, you should take time to support, from the fact that the documentation leaves some empty, they took me a while to realize that control the direction of the robot is in open loop.

Comment only
26 Dec 2009 Juan Luna


I'm trying to enhance (expand) the autonomous mode that controls the NXTway, this by implementing the pure pursuit algorithm, which is executed when these option is chosen.

During the simulation, I found to have some doubts:

1. Why to calculate the current position of the robot you do not use the equation 3.1 on page 7 of document (revision 1.1)?, but instead you use this one:

Z = integral (thetadot * R * cos (phi)) + initial Z;
Y = integral (thetadot * R * sin (phi)) + initial Y

I know that you renamed the coordinates of the robot (pg 56), but despite of the change of coordinates I think the equations are not equivalent.

2. As I could see in the file param_controller.m the maximum linear velocity is 0.3 [m / sec], but you do not put the equivalence with the angular velocity, so: If I put in the gamepad phidot_ref=10, how much it is equivalent in angular velocity?, what I see is that what you do is to add and subtract power to the motors (with a maximum of 25 pwm).

I really appreciate your attention. Thanks in advance, any help you can give me and I am attentive to your answer.

24 Jun 2009 Sam Mirsky

Well done. Good documentation. This demo impresses everyone I show it to.

30 Apr 2009 Yorihisa Yamamoto

> Anand
This file is archived with "Compressed (zipped) folder" shortcut of Windows XP. Please try to decompress it using WinZip or other utilities.

Comment only
28 Apr 2009 Anand

Anand (view profile)

I am not able to unzip this file. please help

Comment only
16 Jul 2008 yipeng tang



28 May 2008 Tatsuya Kikuchi

I watched the Self-Balancing Two-Wheeled Robot at Embedded Systems EXPO in Tokyo. It looked like a clown on a monocycle. I think this robot is joyful study case for students.

17 Mar 2008 Anas Obeidat

it's Excellent Simulation to NXT robot and Documentation is perfect.

11 Mar 2008 Diego Barragán


07 Nov 2008 1.1

1.0 : First edition
1.1 : Added fixed-point controller model
1.2 : modified motion equations

11 Nov 2008 1.2

1.2+ Add an annotation to download the generated code into NXT standard firmware

28 Nov 2008 1.3

Modified the generalized forces and state equations.
Added simulation movie

26 Feb 2009 1.4

updated building instructions
added japanese document

01 May 2009 1.5

1.4 Modified text

Contact us