| Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
| Autor |
Nachricht |
Ford Prefect Moderator


Anmeldungsdatum: 11.01.2006 Beiträge: 1905 Wohnort: ein kleiner Planet in der Nähe von Beteigeuze
|
Verfasst am: Fr Jan 30, 2009 3:52 pm Titel: Segways, die Ihr selber (!) gebaut habt |
|
|
Hallo, liebe Gemeinde!
Postet doch bitte mal ALLE, die ihr mal einen Segway (nxtWAY) gebaut oder nachgebaut habt, eure
Bilder mit kleiner Baubeschreibung
und eure
Source-Codes
als Textfile bzw. downloadbares NXT-G- Programm hier rein.
GANZ WICHTIG: Nur fertige Lösungen, und besonders der Code ist entscheidend! _________________ Don't Panic!
Gruß,
Ford - "A Kingdom of Heaven if NXC had recursions!" - Prefect
Zuletzt bearbeitet von Ford Prefect am Mi Feb 24, 2010 11:02 pm, insgesamt 5-mal bearbeitet |
|
| Nach oben |
|
 |
mou*NXT*ain Schreibt ab und zu

Anmeldungsdatum: 12.01.2009 Beiträge: 44
|
Verfasst am: Fr Feb 13, 2009 7:36 pm Titel: |
|
|
Also, hier eine Beschreibung des NXTway von Philo. Die Bildist von ihm, ich hab ihn aber mal nachgebaut. Das Prog konnte ich nicht verändern, da ich keine Ahnung von NBC habe.
Hier das Programm:
| Code: | //------------------------------------------------
// NXTway - Philo - www.philohome.com - 6/5/2006
//-
dseg segment
// Sensor values
NVal word
offset word
err sdword
errold sdword
errdiff sdword
errint sdword
// Motor values
theUF byte
thePower sbyte
theOM byte OUT_MODE_MOTORON+OUT_MODE_BRAKE
theRM byte OUT_REGMODE_IDLE
theRS byte OUT_RUNSTATE_RUNNING
thePorts byte[] OUT_B, OUT_C // motors B and C
// pid coeffs
kp sdword 30
kd sdword 35
ki sdword 5
scale sdword 45
// pid value
pid sdword
//temp var
temp sdword
// timer vars
thenTick dword
nowTick dword
dseg ends
thread main
setin IN_TYPE_LIGHT_ACTIVE, IN_2, Type
// initialize motors
set thePower, 0
set theUF, UF_UPDATE_SPEED+UF_UPDATE_MODE
setout thePorts, OutputMode, theOM, RegMode, theRM, RunState, theRS, UpdateFlags, theUF, Power, thePower
set theUF, UF_UPDATE_SPEED
// wait a bit to let sensor stabilize
gettick nowTick
add thenTick, nowTick, 100 // wait 100 ms
Waiting:
gettick nowTick
brcmp LT, Waiting, nowTick, thenTick
// reads center value. NXTway must be balanced.
getin NVal, IN_2, NormalizedValue // More precise than PercentValue
mov offset, NVal
Forever:
getin NVal, IN_2, NormalizedValue // read sensor values
sub err, NVal, offset // Substract center value
brtst GT, ErrPos, err // Linearize value
mul err, err, 16 // (less variation if far from surface)
div err, err, 10
ErrPos:
sub errdiff, err, errold // Compute differential error
mov errold, err
add errint, errint, err // Compute integral error
mul errint, errint, 2 // (with fast damping)
div errint, errint, 3
mul pid, kd, errdiff // Differential component
mul temp, kp, err // Proportionnnal component
add pid, pid, temp // Add Diff+Prop
mul temp, ki, errint // Integral component
add pid, pid, temp // Add int
div pid, pid, scale // Scale PID value
// saturate over 100 and under -100
brcmp LT, under100, pid, 100
mov pid, 100
under100:
brcmp GT, overMin100, pid, -100
mov pid, -100
overMin100:
mov thePower, pid // Update motor power
setout thePorts, UpdateFlags, theUF, Power, thePower
jmp Forever
exit
endt
| [/img] _________________ Language: NXT-G 1.1<br>
NXT's: 1x8527<br>
FW: LEGO FW 1.5<br>
Add. Sensors: -<br>
BT: ON |
|
| Nach oben |
|
 |
Ford Prefect Moderator


Anmeldungsdatum: 11.01.2006 Beiträge: 1905 Wohnort: ein kleiner Planet in der Nähe von Beteigeuze
|
Verfasst am: Di Apr 07, 2009 9:24 pm Titel: |
|
|
ein Modell von sgc, auch mit Lichtsensor:
http://www.youtube.com/watch?v=u5qqFkoz40Y
zuerst das Hilfs-File, dann 2 nxtway-Versionen:
| Code: | //******************************************************************************//
// //
// ROBOTC WRITE FILE UTILITIES //
// Robotics Academy of Carnegie Mellon University //
// //
//******************************************************************************//
//******************************************************************************//
// //
// VARIABLES DECLARATIONS //
// //
//******************************************************************************//
const int MaxFileSize = 50000; // file size
bool bFirstNumberOnLine = true;
TFileIOResult nIoResult = ioRsltSuccess;
TFileHandle hFileWriteHandle = NOT_A_HANDLE;
//******************************************************************************//
// //
// PROTOTYPES DECLARATIONS //
// //
//******************************************************************************//
bool createTextFile(const string &sFileName, int nFileSize);
void closeWriteTextFile();
void writeNewLine();
void writeIntegerNumber(long nNumber);
void writeFloatNumber(float fNumber);
//******************************************************************************//
// //
// FILE AND MEASUREMENTS UTILITIES //
// //
//******************************************************************************//
bool createTextFile(const string &sFileName, int nFileSize)
{
bFirstNumberOnLine = true;
Delete(sFileName, nIoResult);
OpenWrite(hFileWriteHandle, nIoResult, sFileName, nFileSize);
return nIoResult == ioRsltSuccess;
}
void closeWriteTextFile()
{
Close(hFileWriteHandle, nIoResult);
hFileWriteHandle = NOT_A_HANDLE;
}
// WRITES CARRIAGE RETURN AND NEW LINE CHARACTERS TO START A NEW LINE
void writeNewLine()
{
WriteText(hFileWriteHandle, nIoResult, "\r\n");
bFirstNumberOnLine = true;
return;
}
// IF REQUIRED, WRITES A DELIMITER BETWEEN NUMBERS ON SAME LINE
void writeDelimiterBetweenNumbers()
{
if (bFirstNumberOnLine)
bFirstNumberOnLine = false;
else
WriteText(hFileWriteHandle, nIoResult, " "); // delimiter
return;
}
// WRITES AN INTEGER TO THE FILE
void writeIntegerNumber(long nNumber)
{
string sTemp;
writeDelimiterBetweenNumbers();
//
// Modify format code ("%d") if you want to change the format - say to line up the
// columns for your application; e.g. "%5d" will make every number five characters.
//
StringFormat(sTemp, "%d", (long) nNumber);
WriteText(hFileWriteHandle, nIoResult, sTemp);
return;
}
// WRITES A FLOATING POINT NUMBER TO THE LINE
void writeFloatNumber(float fNumber)
{
string sTemp;
writeDelimiterBetweenNumbers();
StringFormat(sTemp, "%.2f", fNumber);
WriteText(hFileWriteHandle, nIoResult, sTemp);
return;
}
|
| Code: | //*!!Sensor, S2, lightSensor, sensorLightActive, , !!*//
//*!Motor, motorB, motorB, tmotorNxtEncoderClosedLoop, !*//
//*!Motor, motorC, motorC, tmotorNxtEncoderClosedLoop, !*//
//*! !*//
//*!Start automatically generated configuration code. !*//
const tSensors lightSensor = (tSensors) S2; //sensorLightActive //*!*//
const tMotor motorB = (tMotor) motorB; //tmotorNxtEncoderClosedLoop //*!*//
const tMotor motorC = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!*//
//******************************************************************************//
// LEGO-SEGWAY NXT //
// (source for RobotC) //
// v. 071104 //
// //
// SIMONE CASALE BRUNET //
// casalebrunet[at]gmail[dot]com //
// //
//******************************************************************************//
// BLOCK DIAGRAM: //
// ================ //
// //
// //
// reference error .-. power .-. position //
// ->(+/-)->|DIGITAL CONTROL |->| MOTORS |-> //
// ^ .-. .-. | //
// | | //
// | | //
// ;-; //
// //
// //
//******************************************************************************//
// NOTES: //
// ======== //
// //
// 1. Be sure to set the reference value: you can use light_mean.c to take //
// some measurements and than calculate the mean value with Matlab //
// 2. If you use a PID or PI control law be sure to set the right coefficients //
// //
//******************************************************************************//
// MOTORS & SENSORS: //
// ================= //
// //
// To modify Motors & Sensors Configuration in Robot C, go to View -> Motors //
// & Sensors Setup. This will change the automatically generated code. //
// //
// [I/O PORT] [Name] [Type] //
// Sensor,S2 lightSensor Light sensor, Light Active //
// Motor,motorB motorB NXT motor with speed control //
// Motor,motorC motorC NXT motor with speed control //
// //
//******************************************************************************//
//******************************************************************************//
// //
// VARIABLES DECLARATIONS //
// //
//******************************************************************************//
#pragma platform(NXT)
#include "writeFile.c"
// CLOSED LOOP SIGNALS
const int reference = 480;
int position = 0;
float error = 0.0;
float old_error = 0.0;
float command = 0.0;
// SAMPLING TIME [ms]
const int Ts = 5;
// PID COEFFICIENTS:
const float kp = 1500.0;
const float ki = 200.0;
const float kd = 100.0;
const float scale = 3100.0;
const float decayInt = 6.0;
const float tDelta = 16.0;
// GLOBAL VARIABLES
float int_error = 0.0;
float dif_error = 0.0;
int buffPosition = 0;
int meanPosition = 0;
// FILE DATA
const string sFileName = "data.txt"; // file name
const int measures = 5000; // measures that will be taken
//******************************************************************************//
// //
// PROTOTYPES DECLARATIONS //
// //
//******************************************************************************//
// BALANCING FUNCTIONS
void balance();
void controlLaw();
void maxRange();
void shutDown();
void scbTrigger();
void moveMotors();
void initRbt();
// SAVE DATA IN THE LOG FILE
void saveData();
//******************************************************************************//
// //
// BALANCING THE SEGWAY-LEGO //
// //
//******************************************************************************//
// INITIALIZE THE LEGO-SEGWAY
void initRbt(){
bFloatDuringInactiveMotorPWM = false; // motors will brake when inactive
nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg; // enables motorB speed regulation
nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg; // enables motorC speed regulation
nSyncedMotors = synchBC; // "C" will be synchronized to "B".
nSyncedTurnRatio = 100;
nPidUpdateInterval = Ts; // Best performance if we do really frequent updates
createTextFile(sFileName, MaxFileSize);
writeIntegerNumber(reference); // save reference value in the file
writeNewLine();
PlayTone(200, 10); // NXT, THIS IS HOUSTON. YOU ARE GO!
PlayTone(250, 10);
PlayTone(100, 10);
PlayTone(150, 10);
wait1Msec(3000); // wait 3 sec
}
// SAVE DATA IN THE LOG FILE
void saveData(){
writeIntegerNumber(position);
writeIntegerNumber((int)command);
writeNewLine();
}
// ALL SYSTEMS OFF
void shutDown(){
closeWriteTextFile();
motor[motorB] = 0;
motor[motorC] = 0;
}
// CHECK IF THE COMMAND IS IN RANGE
void maxRange(){
if (command > 100.0){
command = 100.0;
}
else if (command < -100.0){
command = -100.0;
}
}
// SCB's TRIGGER: REDUCE THE NOISE
void scbTrigger(){
if(abs(buffPosition-position)>3){
position = buffPosition;
}
}
// MOVE MOTORS
void moveMotors(){ motor[motorB] = (int)command; }
// BALANCE THE LEGO-SEGWAY
void balance(){
int count = 0;
int tick = 1;
while(nNxtButtonPressed!=3){
buffPosition = SensorRaw(lightSensor); // take the actual position
scbTrigger(); // use the scb Trigger
meanPosition += position;
if(tick == Ts){
position = meanPosition/Ts;
controlLaw(); // generate the command signal
maxRange(); // check if the command is in range [-100:+100]
if(count<measures){ // save data
saveData();
count++;
}
meanPosition = 0.0;
tick = 0;
moveMotors(); // move the motors
}
eraseDisplay();
nxtDisplayBigStringAt(40, 30, "%d", (int)command);
tick++;
}
}
// CONTROL LAW'S ALGORITHM
void controlLaw(){
error = reference - position; // Proportional Error
if (error < 0) error = error * 16 / 10; // Adjust far and near light readings:
int_error += error - int_error * decayInt / 100;
dif_error = error-old_error;
command = (kp * error + ki * int_error + kd * dif_error) / scale; // Command Signal
old_error= error;
}
// MAIN TASK
task main()
{
initRbt();
balance();
shutDown();
}
|
| Code: | //*!!Sensor, S2, lightSensor, sensorLightActive, , !!*//
//*!Motor, motorB, motorB, tmotorNxtEncoderClosedLoop, !*//
//*!Motor, motorC, motorC, tmotorNxtEncoderClosedLoop, !*//
//*! !*//
//*!Start automatically generated configuration code. !*//
const tSensors lightSensor = (tSensors) S2; //sensorLightActive //*!*//
const tMotor motorB = (tMotor) motorB; //tmotorNxtEncoderClosedLoop //*!*//
const tMotor motorC = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!*//
//******************************************************************************//
// LEGO-SEGWAY NXT //
// (source for RobotC) //
// v. 071104 //
// //
// SIMONE CASALE BRUNET //
// casalebrunet[at]gmail[dot]com //
// //
//******************************************************************************//
// BLOCK DIAGRAM: //
// ================ //
// //
// //
// reference error .-. power .-. position //
// ->(+/-)->|DIGITAL CONTROL |->| MOTORS |-> //
// ^ .-. .-. | //
// | | //
// | | //
// ;-; //
// //
// //
//******************************************************************************//
// NOTES: //
// ======== //
// //
// 1. Be sure to set the reference value: you can use light_mean.c to take //
// some measurements and than calculate the mean value with Matlab //
// 2. If you use a PID or PI control law be sure to set the right coefficients //
// //
//******************************************************************************//
// MOTORS & SENSORS: //
// ================= //
// //
// To modify Motors & Sensors Configuration in Robot C, go to View -> Motors //
// & Sensors Setup. This will change the automatically generated code. //
// //
// [I/O PORT] [Name] [Type] //
// Sensor,S2 lightSensor Light sensor, Light Active //
// Motor,motorB motorB NXT motor with speed control //
// Motor,motorC motorC NXT motor with speed control //
// //
//******************************************************************************//
//******************************************************************************//
// //
// VARIABLES DECLARATIONS //
// //
//******************************************************************************//
#pragma platform(NXT)
#include "writeFile.c"
// CLOSED LOOP SIGNALS
const int reference = 480;
int position = 0;
float error = 0.0;
float command = 0.0;
// SAMPLING TIME [ms]
const int Ts = 5;
// PI COEFFICIENTS:
const float kp = 1895.0;
const float ki = 200.0;
const float scale = 3100.0;
const float decayInt = 6.0;
const float tDelta = 16.0;
// GLOBAL VARIABLES
float int_error = 0.0;
int buffPosition = 0;
int meanPosition = 0;
// FILE DATA
const string sFileName = "data.txt"; // file name
const int measures = 5000; // measures that will be taken
//******************************************************************************//
// //
// PROTOTYPES DECLARATIONS //
// //
//******************************************************************************//
// BALANCING FUNCTIONS
void balance();
void controlLaw();
void maxRange();
void shutDown();
void scbTrigger();
void moveMotors();
void initRbt();
// SAVE DATA IN THE LOG FILE
void saveData();
//******************************************************************************//
// //
// BALANCING THE SEGWAY-LEGO //
// //
//******************************************************************************//
// INITIALIZE THE LEGO-SEGWAY
void initRbt(){
bFloatDuringInactiveMotorPWM = false; // motors will brake when inactive
nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg; // enables motorB speed regulation
nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg; // enables motorC speed regulation
nSyncedMotors = synchBC; // "C" will be synchronized to "B".
nSyncedTurnRatio = 100;
nPidUpdateInterval = Ts; // Best performance if we do really frequent updates
createTextFile(sFileName, MaxFileSize);
writeIntegerNumber(reference); // save reference value in the file
writeNewLine();
PlayTone(200, 10); // NXT, THIS IS HOUSTON. YOU ARE GO!
PlayTone(250, 10);
PlayTone(100, 10);
PlayTone(150, 10);
wait1Msec(3000); // wait 3 sec
}
// SAVE DATA IN THE LOG FILE
void saveData(){
writeIntegerNumber(position);
writeIntegerNumber((int)command);
writeNewLine();
}
// ALL SYSTEMS OFF
void shutDown(){
closeWriteTextFile();
motor[motorB] = 0;
motor[motorC] = 0;
}
// CHECK IF THE COMMAND IS IN RANGE
void maxRange(){
if (command > 100.0){
command = 100.0;
}
else if (command < -100.0){
command = -100.0;
}
}
// SCB's TRIGGER: REDUCE THE NOISE
void scbTrigger(){
if(abs(buffPosition-position)>3){
position = buffPosition;
}
}
// MOVE MOTORS
void moveMotors(){ motor[motorB] = (int)command; }
// BALANCE THE LEGO-SEGWAY
void balance(){
int count = 0;
int tick = 1;
while(nNxtButtonPressed!=3){
buffPosition = SensorRaw(lightSensor); // take the actual position
scbTrigger(); // use the scb Trigger
meanPosition += position;
if(tick == Ts){
position = meanPosition/Ts;
controlLaw(); // generate the command signal
maxRange(); // check if the command is in range [-100:+100]
if(count<measures){ // save data
saveData();
count++;
}
meanPosition = 0.0;
tick = 0;
moveMotors(); // move the motors
}
eraseDisplay();
nxtDisplayBigStringAt(40, 30, "%d", (int)command);
tick++;
}
}
// CONTROL LAW'S ALGORITHM
void controlLaw(){
error = reference - position; // Proportional Error
if (error < 0) error = error * 16 / 10; // Adjust far and near light readings:
int_error += error - int_error * decayInt / 100;
command = (kp * error + ki * int_error) / scale; // Command Signal
}
// MAIN TASK
task main()
{
initRbt();
balance();
shutDown();
}
|
_________________ Don't Panic!
Gruß,
Ford - "A Kingdom of Heaven if NXC had recursions!" - Prefect |
|
| Nach oben |
|
 |
togi Schreibt ab und zu


Anmeldungsdatum: 09.06.2009 Beiträge: 25 Wohnort: Germany
|
Verfasst am: Fr Feb 26, 2010 5:51 pm Titel: |
|
|
Hallo,
hier ist noch ein cooles Gefährt mit Kompas von der Fachhochschule Nordwestschweiz.
http://web.fhnw.ch/technik/projekte/eit/Herbst2007/BruWid/Flash/NXT%20Standalone.swf
Allerdings leider ohne Sourcecode.
Viellieicht kannst Du Sie anschreiben und fragen ob Du den Sourcecode
bekommen könntest. Sieht so auf als wenn sie es mit LabView realisiert
haben.
Grüße _________________ „Mathematik ist die perfekte Methode, sich selbst an der Nase herum zu führen.“
Albert Einstein |
|
| Nach oben |
|
 |
Ford Prefect Moderator


Anmeldungsdatum: 11.01.2006 Beiträge: 1905 Wohnort: ein kleiner Planet in der Nähe von Beteigeuze
|
Verfasst am: Sa März 06, 2010 11:51 pm Titel: |
|
|
nur als Querverweis: hier ein Thread aus nxtasy, der sich mit diesem Thema beschäftigt - mit Referenz über Filtertechniken:
http://forums.nxtasy.org/index.php?showtopic=4941 _________________ Don't Panic!
Gruß,
Ford - "A Kingdom of Heaven if NXC had recursions!" - Prefect |
|
| Nach oben |
|
 |
segpete Schreibt ab und zu


Anmeldungsdatum: 14.02.2008 Beiträge: 29
|
Verfasst am: Mo März 29, 2010 2:18 pm Titel: |
|
|
Hey Leute,
ich habe heute eine Präsentation zum Thema: "Demonstration der Funktionsweise eines Segways mit Hilfe der Programmierung eines Lego Mindstorms Roboters" für mein Abitur gehalten, folgendes war mein Ergebnis:
http://nxt.meinblock.eu/artikel-8.html
Dort ist der Quelltext zu finden, ein Video und auch die Präsentation als .pdf. Der Text ist leider noch nicht fertig, der kommt die Tage, denn ich habe jetzt erstmal Ferien
Viele Grüße _________________ nxt.meinblock.eu - meine informative NXT-Projekte Seite |
|
| Nach oben |
|
 |
Ford Prefect Moderator


Anmeldungsdatum: 11.01.2006 Beiträge: 1905 Wohnort: ein kleiner Planet in der Nähe von Beteigeuze
|
Verfasst am: Mo März 29, 2010 3:01 pm Titel: |
|
|
sehr schöne Lösung, Glückwunsch!
wenn das mal keine 15 Punkte werden... :) _________________ Don't Panic!
Gruß,
Ford - "A Kingdom of Heaven if NXC had recursions!" - Prefect |
|
| Nach oben |
|
 |
|
|
Sie können keine Beiträge in dieses Forum schreiben. Sie können auf Beiträge in diesem Forum nicht antworten. Sie können Ihre Beiträge in diesem Forum nicht bearbeiten. Sie können Ihre Beiträge in diesem Forum nicht löschen. Sie können an Umfragen in diesem Forum nicht mitmachen.
|
|
|