Let's Make Robots!

The Tale of One Pleased Robot Owner

 

I can't tell you how much I am enjoying this FEZ Mini Robot!

My coding in C# is rapidly improving and now I can do just about anything I want, it compiles (not even many warnings!) and runs great on the robot. The Microsoft emulator no longer puts out those error messages (as long as the hardware is attached to the system.)

When I started out I thought maybe I couldn't learn C# but I am happy to be wrong about that. I still have a LOT to learn in C#, but my desire to learn it is VERY strong.

It's true, FEZ is Fricking Easy! :-)

I had to get the mini board with the robot, but now I want a bigger FEZ board in a bigger robot.

UPDATE: This is better than I could have ever expected! This thread has now become a discussion from beginner (me) to seasoned programmer (Geir) about programming in C#. Others are becoming involved now too. That is sooooo cool!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The example you gave me ran fine and debugged without a problem.

I can send any program to the FEZ without a problem. It is only after starting to debug a bad program and it runs for a while does the debugger crash. It always shows the error as being on of the provided source files (liks led.c) and NOT in my program (the debugger switches its display to the failing program and code after it crashes).

I know all the programs like led.c are working becuase I use them in my working program.

Confusing? Yes it is really bad for me a C# neophyte. (I am trying to learn scope of variables right now.)

(My program doesn't look THAT bad and at least it all runs great on my robot...)

Back to studying,,,

I don’t know if this is an issue, but you reassign some analoge pins in this function

static void mood(double value, int dist, int caut, int turn)
        {
            FEZ_Components.LED myGreen = new FEZ_Components.LED(FEZ_Pin.Digital.An4);
            FEZ_Components.LED myRed = new FEZ_Components.LED(FEZ_Pin.Digital.An5);
 .....

So you might want to move the myGreen & myRed up as a global object like this

namespace tryFunc1
{
    public class Program
    {
       static FEZ_Components.LED myGreen = new FEZ_Components.LED(FEZ_Pin.Digital.An4);
       staticFEZ_Components.LED myRed = new FEZ_Components.LED(FEZ_Pin.Digital.An5);

        static void Main()
        {
            FEZ_Components.ServoMotor myServo = new FEZ_Components.ServoMotor(FEZ_Pin.Digital.Di8);
  ...

That helps show me more of function structure. (I also have been redefineing pins and I know the warning not to assign 2 functions to the same pin at one time. Wonder if that could blow a pin?)

I want to ask:

 

using System;

using Microsoft.SPOT;

namespace justJunk1

{

    public class Program

    {

        int a = 0;

        static void Main()

        {

            a++;

        }

 

       void fun()

        {

            a++;

        }

 

        void fun2()

        {

            a++;

        }

 

    }

}

In this small example program, I know by defining "a" publicly all the little routines can make use of it. The question/problem is this variable is having "strange" problems in main. I thought it would just as easily be available there.
It seems easy to create the functions, its just passing the variables that causes me severe problems. (Primarily variable type and scope.) 
Thanks again.

 

I think that if you changed the

 int a = 0;

to

static  int a = 0;

it would compile just fine... but I maybe wrong.

That works just fine! With that, true public variables are posssible. I know one should try NOT to use them, but at times they can turn a hard, complex solution into a relatively simple one. I very much needed that capability.

As usual, you saved the day (you should be getting used to doing that) :-)

Thanks again, my friend.

 

As of my most recent compile, MY ENTIRE PROGRAM IS ALMOST ALL FUNCTIONS (methods?) !!!!

Even the "harder" functions are working as they should ( avg(), mood() etc)

(Man, have I ever learned a LOT of C#!!!!)  Now I want that Panda II board!!!! :-)

A BIG thanks goes to you for getting me to this point!

Your (want to write more C#) friend, Will.

 

This is something off our beaten path. I updated the discussion topic intro expressing my pleasure as to which way this conversation has gone. You didn't want me to call you a guru (in my book you are) so I refered to you as a "seasoned programmer" and thought you wouldn't mind that.

I just noticed my working program debugs just fine! No debugger crash and you can set breakpoints and do all the other stuff. It is the broken program that crashes the debugger consistantly! 

Until I (slowly) learn more about C#, I am going to consider my program to be functional code.(It may not be "pure" C# code, but right now I don't know how to write better code.

I did find another guy on the web who made a tranformed a RC car to a FEZ Mini based robot and he was kind enough to put his code up. With 2 or 3 functions at the end of the program (I can do that!), most of his coding was simple and linear.

I strongly suspect that a lot of code for the FEZ Mini WILL be written in a fairly linear fashion. What I really like is the robot will function so well like that. That truly is "Fast and Easy" programming (I saw A LOT of Arduino scripts written in that fashion.)

Thanks again for all the great help and expect me to be back from time to time with more questions.

There is nothing wrong with linear code. Most C# NETMF code will probably have a main while (true) loop as a backbone and other functions and threads doing work in the background.

It’s better to write code that’s easy to read, than some fancy smancy code that is hard to follow.

There might still be room for improvement in your code as these two code block could probably be written as a single function?


                myGreen.TurnOn();
                myRed.ShutOff();

                for (y = 170; y > 110; y = (byte)(y - 10))
                {
                    anaSensorReading = anaIn.Read();

                    myServo.SetPosition(y);
                    Debug.Print("Angle: " + y.ToString());
                    Thread.Sleep(100);
                    value = avg(10);
                    mood(value, dist, caut, turn);
                    if ((value < turn) | (anaSensorReading < 50))
                    {
                        anaSensorReading = 100;

                        FEZMini_Robot.Move(0, 0);

                        FEZMini_Robot.MoveRamp(n1, n2, 10); // negative to reverse and ramp
                        Thread.Sleep(50); // how long to backup

                        turn_right(200);

                        stop();

                        beep();

                        FEZMini_Robot.MoveRamp(m1, m2, 10);

                        Thread.Sleep(10);
                    }
                }

Your doing great Will so just keep up the good work and post a question if you need help.
Geir

 

First, you do know that is a section of my BAD code that won't run on the robot! It is horrible code and I hope nobody attemps to see how to write a C# program because they will create a program that won't run!!! :-)

I cannot seem to make work the "value=avg(10)" function or the "mood(value, dist, caut, turn)" without major compile errors (I got them to compile in the bad program but I am pretty sure neither one actually works.}

I am having huge amounts of problems with the "scope" of variables. I find myself wishing for real "global" variables usable and recognized in any part of the program. I see C# doesn't like that and then the scope thing just kills me...

I am pretty sure I CAN'T combine those 2 code blocks (at least without the program getting trashed and unrunnable.

Thanks again for being there, and I bet you couldn't guess how hard it was going to be to help ME learn C#. (Big smilie here.)