Shop OBEX P1 Docs P2 Docs Learn Events
The Teacup Port - A Work In Progress - 3D Printer Firmware — Parallax Forums

The Teacup Port - A Work In Progress - 3D Printer Firmware

idbruceidbruce Posts: 6,197
edited 2015-04-08 23:16 in Propeller 1
Hello Everyone

Please keep in mind that this is a work in progress, however I do believe that I have a good overview of what needs to be done. At this time, a large portion of the critical components, of the Teacup firmware, have been ported to SPIN, but I know the ported parts contain errors that need to be fixed and the code needs to be tied together.

Anyhow I have attached an archive, just in case that some of you may want to participate in the discussion of or the development of this firmware, with the caveat that many of the settings and hardware associated with those setting are geared towards the use of the controller discussed at this thread: http://forums.parallax.com/showthread.php/155404-Input-Needed-Combining-Propeller-Proto-Board-Prop-DIP-40-and-ADC-for-3D-Printer, however the settings and hardware can be altered to ones particular needs or setup.

There are several threads throughout the forum that apply to many different aspects of my 3D printer project, but this thread will particularly pertain to the firmware required to run the machine. As needed or as requested for information, I will provide links to various other discussions throughout the forum that are pertinent.

At the current point, I am taking the coordinates and converting them to intergers, which will then be converted to the required number of steps to make a targeted move, followed by the calculations for linear interpolation. Much of the code has been ported for all of this, but as mentioned, there will be mistakes, bugs, and the necessity to tie it altogether and make it functional.

During the conversion of coordinates to integers, a mistake is occuring, which places the negative sign within the middle of the conversion. To follow along with this discussion, it will be necessary to locate the following source within the Parse method, but more specifically the call within that source to the ProcessCoordinate method.
    IF(bFieldElement_4 == 0)
      Terminal.Str(STRING("NULL"))

    ELSE
      Terminal.Str(@bFieldElement_4)
      'MySteps := ConvertDifferenceToSteps(@bFieldElement_4)
      'lPreviousX_Location := @bFieldElement_4
      Terminal.Tx(32) {Space}
      
      Mantissa := ProcessCoordinate(@bFieldElement_4)
      Terminal.Dec(Mantissa)

EDIT: Before I go any further, I want to make sure, I want to make sure that the proper people get credit, and I want to make others aware of the licensing issues. Throughout this thread, there will be numerous references to portions of the Teacup firmware, and hopefully this inclusion of the credit and licensing information will satisfy everyones requirements.
##############################################################################
#                                                                            #
# Teacup - lean and efficient firmware for RepRap printers                   #
#                                                                            #
# by Triffid Hunter, Traumflug, jakepoz, Markus Hitter, many others          #
#                                                                            #
##############################################################################

For installation instructions, see
http://reprap.org/wiki/Teacup_Firmware#Simple_Installation and/or
http://reprap.org/wiki/Teacup_Firmware#Developer_Installation

For documentation, see
http://reprap.org/wiki/Teacup_Firmware


##############################################################################
#                                                                            #
# This firmware is Copyright (c) ...                                         #
#   2009 - 2010 Michael Moon aka Triffid_Hunter                              #
#   2010 - 2013 Markus "Traumflug" Hitter <mah@jump-ing.de>                  #
#                                                                            #
# This program is free software; you can redistribute it and/or modify       #
# it under the terms of the GNU General Public License as published by       #
# the Free Software Foundation; either version 2 of the License, or          #
# (at your option) any later version.                                        #
#                                                                            #
# This program is distributed in the hope that it will be useful,            #
# but WITHOUT ANY WARRANTY; without even the implied warranty of             #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
# GNU General Public License for more details.                               #
#                                                                            #
# You should have received a copy of the GNU General Public License          #
# along with this program; if not, write to the Free Software                #
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA #
#                                                                            #
##############################################################################
		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) year name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.


I think I have said enough for now, take a peek at the archive. Oh and I threw a bare minimum G-Code file in the archive, with the name MINIMUM.TXT for fast testing purposes
«13456789

Comments

  • idbruceidbruce Posts: 6,197
    edited 2015-02-03 04:35
    During the conversion of coordinates to integers, a mistake is occuring, which places the negative sign within the middle of the conversion.

    This mistake was due to a terminal output that I was using for test purposes, and the offending source is located within the ProcessCoordinate method.

    Change
      WHILE((Char => "0") AND (Char =< "9")) OR (Char == ".") OR (Char == "-")
    
      Terminal.Dec(lMantissa)
    

    To
      WHILE((Char => "0") AND (Char =< "9")) OR (Char == ".") OR (Char == "-")
    
  • idbruceidbruce Posts: 6,197
    edited 2015-02-03 11:13
    My current endeavor is to resolve a programming error within the MulDivQR method, because it is returning zero, instead of the accurate answer of 4321 steps to make a 77.77mm targeted move.

    The sequence of events is as follows:

    A target value is parsed from a G-Code file and then converted into an integer by the ProcessCoordinate method. The return of that method, along with several other parameters, are sent to the uM_DistanceToStepConversion method, which then passes those values along to the MulDivQR method to obtain the actual number of required steps.

    I believe the error contained within MulDivQR is one of the following shifts or and:
    Multiplicand & 1
    Multiplicand >>= 1
    Qn <<= 1
    Rn <<= 1

    Anyhow, I have created a very small spin program to help me resolve this issue and I am now attaching it, just in case anyone is interested or wants to help.

    EDIT: Additionally, here is the equivalent function in C++ MFC, which does provide the correct answer:
    __int32 CUm2StepsDlg::MulDivQR(__int32 Multiplicand, unsigned int Qn, unsigned int Rn, unsigned int Divisor)
    {
    	unsigned int Quotient = 0;
    	unsigned int Remainder = 0;
    	unsigned char Negative_flag = 0;
    
    	if (Multiplicand < 0)
    	{
    		Negative_flag = 1;
    		Multiplicand = -Multiplicand;
    	}
    
    	while(Multiplicand)
    	{
    		if (Multiplicand & 1)
    		{
    			Quotient += Qn;
    			Remainder += Rn;
    			if (Remainder >= Divisor)
    			{
    				Quotient++;
    				Remainder -= Divisor;
    			}
    		}
        
    		Multiplicand  >>= 1;
    		Qn <<= 1;
    		Rn <<= 1;
        
    		if (Rn >= Divisor)
    		{
    			Qn++; 
    			Rn -= Divisor;
    		}
        }
    
    	// rounding
    	if (Remainder > Divisor / 2)
    	{
    		Quotient++;
    	}
    
    	return Negative_flag ? -((__int32)Quotient) : (__int32)Quotient;
    }
    
  • JonnyMacJonnyMac Posts: 8,927
    edited 2015-02-03 12:39
    WHILE((Char => "0") AND (Char =< "9")) OR (Char == ".") OR (Char == "-")
    


    Checks like that can become tedius and are prone to errors (ask me how I know!). I have a little method called cinstr() in my strings library that I use while parsing.
    pub cinstr(p_str, c) | pos
    
    '' Returns position of character c in string at p_str
    '' -- returns -1 if not found
    
      pos := 0
    
      repeat strsize(p_str)                                          ' loop through string chars
        if (byte[p_str][pos] == c)                                   ' if match
          return pos                                                 ' return position
        pos += 1
    
      return -1                                                      ' return not found
    


    Will I tend to pass it the pointer to a pre-defined string (DAT table), you can use an inline string as well.
    while (cinstr(string("0123456789.-", char) => 0)
        ' do something
    


    Admittedly, it's probably not as fast as a simple comparison, but it really helps out when the valid character set becomes complex.
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-02-03 12:51
    Bruce, you have fallen into the Spin ">=" trap. Change ">=" to "=>" in the two places you are using it.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-03 13:17
    Jon

    As you know, the nice thing about having 8 cogs, is the ability to parallel process. It is my intention to keep the parsing and movements in seperate cogs, and the movements will be much slower than the parsing, so I should have a wide margin of time in the parsing cog to perform extra tasks, so the speed of parsing really is not the issue, as it might be for other uCs.

    In all honesty Jon, I do respect your knowledge, experience, and wisdom of programming. Although I have not had problems when the comparisons and operators are correct, doesn't mean that problems or errors cannot occur, because I am certain that your programming knowledge is much broader than mine. In C++ MFC, the CString class has the Find method, which is basically equivalent to the function you show and I have used quite often in the past, because it was fast, reliable, and simple to use.
    Admittedly, it's probably not as fast as a simple comparison, but it really helps out when the valid character set becomes complex.

    Admittedly, I do not to slow anything down, unless absolutely necessary or wise to do so. Do you think I should change that comparison to the code you shown? If so, I will.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-03 13:25
    Dave

    That is FANTASTIC!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Another major problem resolved!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    SWEET!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    THANK YOU VERY MUCH!!!!!!!!!!!!!!!!!!!!!!

    Equating stepper steps to distance, now that is advancement. Time now for linear interpolation :)
  • JonnyMacJonnyMac Posts: 8,927
    edited 2015-02-03 14:28
    Do you think I should change that comparison to the code you shown? If so, I will.

    That's completely up to you; I just wanted to show you another way to do what you're doing that bypasses the => and =< traps (that we all fall into). It's interesting that you note the use of the find() function; I'm pretty sure I translated cinstr() from a C library somewhere.

    I just finished a generic parsing object that I will write about in my next Nuts & Volts column. In that the setup of that object you pass a pointer to a string of valid characters, and a poitner to your list of valid tokens. Parsing the tokens out requires searching the valid characters; in the is case cinstr() was necessary.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-03 15:03
    Jon

    If I was starting from scratch, I would definitely take your advice from this post: http://forums.parallax.com/showthread.php/159947-HELP.spin-I-Am-Going-In-Circles-And-Getting-Dizzy-Byte-Array?p=1313935&viewfull=1#post1313935 and combine it with your last post of this thread. It definitely would have been the way to go.
    I just finished a generic parsing object that I will write about in my next Nuts & Volts column. In that the setup of that object you pass a pointer to a string of valid characters, and a poitner to your list of valid tokens. Parsing the tokens out requires searching the valid characters; in the is case cinstr() was necessary.

    Sounds very interesting. I have done similar stuff in the past with PERL and it was very effective, but I forget the exact details. However, when it comes to parsing and manipulating strings, nothing beats CString, because you have such a wide array of methods to choose from. I almost believe there is nothing you cannot do with CString. Take a peek at this Microsoft page and you will see what I mean: https://msdn.microsoft.com/en-us/library/aa315043(v=vs.60).aspx

    In addition to CString, there was also the CStringArray and CStringList classes, with their own wide array of member functions.

    I really got spoiled with MFC :) and programming with SPIN can be real problematic at times :(
  • idbruceidbruce Posts: 6,197
    edited 2015-02-03 15:14
    As I progress with this project, I have been keeping a very close eye on RAM usage. Here is a pic of the current state.
    attachment.php?attachmentid=113061&d=1423005267
    315 x 430 - 26K
  • idbruceidbruce Posts: 6,197
    edited 2015-02-04 01:07
    After spending several hours working on a port for dda.c, I must say that is one very interesting file, and I am a long way from being finished :)
  • idbruceidbruce Posts: 6,197
    edited 2015-02-04 16:15
    Alright, that was some serious drudgery.

    In the archive below, you will find the current state of the TeacupPort, with the addition of some G-Code, and a large partial port of dda.c to SPIN. This partial port, is readily viewable and highly readable with the Propeller Tool. There is still some hints of C lingering about, but it was left there intentionally to act as clues in the final porting process.

    For those of you familiar with C/C++, you are well aware that structures are not SPIN compatible, so many of the variables and function names have been changed, but there are serious naming clues to guide, while also referring to dda.c.

    With the exception of not having provisions written for a user interface, I firmly believe that TeacupPort.spin and DDA.spin contain most of the necessary code to get a 3D printer or other CNC machine up and running. However, these files are no where near ready to run a printer or CNC machine. They will still need a quite a bit of work, but I am now much closer than I was a week ago.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-02-05 09:33
    I'm sure you'll get a lot of "here's another way to do this" and I'm adding one more.
          ELSEIF(Char == 84 {T Character})
    
            'Set current field element
            Field_Element := 2
            bValidFields[2] := 1
            Index++
            NEXT
    
          ELSEIF(Char == 83 {S Character})
    
            'Set current field element
            Field_Element := 3
            bValidFields[3] := 1
            Index++
            NEXT
    
          ELSEIF(Char == "T")
    
            'Set current field element
            Field_Element := 2
            bValidFields[2] := 1
            Index++
            NEXT
    
          ELSEIF(Char == "S"})
    
            'Set current field element
            Field_Element := 3
            bValidFields[3] := 1
            Index++
            NEXT
    

    By using the actual characters rather than the ASCII code, you don't need to add a comment about what the ASCII code means.

    Either version of code should behave the same once compiled so I suppose which version to use is a matter of personal preference.

    Edit: One more thing. I'm pretty sure none of the "NEXT" statements in that method are needed. I think these unneeded statements might slow the code down on top of using valuable RAM.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-05 11:57
    Duane

    :) Thanks for the tip on the characters, however I actually did know that, because I think you may have told me that before :) I just have not got to the point of changing it, but I will most definitely change them for the purpose of clarity. As for the NEXT statements, I will also have to go through and weed out the uncessary ones, as you suggest. I knew some of them were unnecessary at first glance, but I did not even think about the ones you pointed out.

    I am making good progress today, but converting all the them C structures to variables and keeping track of them throughout the functions is a real pain. Additionally, it now looks like I will have to port dda_queue.c, because it now appears to run the whole show, but the file is small, so it should not be too bad. Hopefully before too long, I should have something that will at least compile.

    Thanks for the tips Duane.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-05 12:18
    I previously quoted this in another thread, but since it certainly applies to this thread, I will quote it again. As far as I can tell, this description sounds pretty darn accurate.
    At startup, the code in mendel.c is run first. This initialises all the modules that need it, then starts polling the clock flags and feeding incoming serial characters to the gcode parser. The gcode parser processes each character individually, keeping track via internal state rather than buffering a line and skipping back and forth. The gcode parser converts floating values to integer or fixed-point representations as soon as it encounters a non-numeric character. It calls many module functions directly, but the most interesting part is move creation, where it passes a target position and speed to enqueue()[dda_queue.c] which adds it to the queue, and fires up dda_start()[dda.c] if the queue was empty. dda_start initialises the dda, figures out the stepper directions and first step timeout and a few other bits of housekeeping, then sets the timer for the appropriate timeout. When the timer fires, it calls dda_step()[dda.c] which sends all the step signals then figures out the next step timeout based on acceleration and speed settings. When the last step has been made, the dda "dies" (sets 'live' property to 0) after which queue_step[dda_queue.c] advances the queue read pointer and starts the next dda.

    Source: Wikipedia - http://reprap.org/wiki/Teacup_Firmware
  • idbruceidbruce Posts: 6,197
    edited 2015-02-05 21:23
    Since a few people have downloaded the files that I uploaded, I suppose it is only fair to give a heads up notice.

    This is meant to be a bare bones port and all conditional compilation statements will be eliminated. To be more specific, this port will only support ACCELERATION_RAMPING and will not support DC_EXTRUDER as defined within the Teacup firmware. Additionally, although it will not be initially supported, I may add support for LOOKAHEAD in the future, but I believe at this point, it is strictly experimental.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-06 05:53
    I am a little indecisive at the moment, concerning limit, overtravel, and homing switches, and I am at a point in the port, where a decision must be made.

    Considering that I finish this port and considering that it functions like it should, there should be no reason that this code could not be adapted to run small CNC machines (depending on the G-Codes required). And in my opinion, any software intended to run a CNC machine or a 3D printer (also CNC :) ) for that matter, should be able to detect limit switches.

    As it pertains to the controller linked to in the first post of this thread, the following source code would be deemed incompatible, considering that all the over-travel switches and ESTOP are monitored by a single pin. In reality, I would have liked seperate input for the switches, but I ran out of available pins. Anyhow, the 3D printer that I am building, will not be using limit switches, however I believe I should add support for the limit switches, just to save someone a lot of grief later.

    Considering that I do want to add support for limit switches, it now becomes an issue of ifs, ors, elses, all based upon constants. With the exception of a few unapplicable constants, the following code contains seven constants that are directly related to limit switch monitoring. Without any doubt, I can achieve a solution to adapt the following code to SPIN, but I doubt it would be the ideal solution, so I am open to to any solutions from those knowledgable about programming in SPIN.

    EDIT: I do realize that I can easily implement this code by adding six or seven more constants, but I do not consider that to be an ideal solution.

    EDIT: Additonally, there is the option of requiring that no limit switches be tied to IO 0, then the constants could be compared against 0.

    EDIT: I figured it out. If a limit switch is not present, the value is -1, otherwise the switch is present.
    	if(dda->endstop_check && !move_state.endstop_stop)
    	{
    		#if defined X_MIN_PIN || defined X_MAX_PIN
    		
    		if(dda->endstop_check & 0x1)
    		{
    			#if defined X_MIN_PIN
    
    			if(x_min() == dda->endstop_stop_cond)
    			{
    				move_state.debounce_count_xmin++;
    			}
    			else
    			{
    				move_state.debounce_count_xmin = 0;
    			}
    
    			#endif
    
    			#if defined X_MAX_PIN
    
    			if(x_max() == dda->endstop_stop_cond)
    			{
    				move_state.debounce_count_xmax++;
    			}
    			else
    			{
    				move_state.debounce_count_xmax = 0;
    			}
    
    			#endif
    
    			endstop_trigger = move_state.debounce_count_xmin >= ENDSTOP_STEPS ||
    				move_state.debounce_count_xmax >= ENDSTOP_STEPS;
    		}
    
    		#endif
    
    		#if defined Y_MIN_PIN || defined Y_MAX_PIN
    
    		if(dda->endstop_check & 0x2)
    		{
    			#if defined Y_MIN_PIN
    
    			if(y_min() == dda->endstop_stop_cond)
    			{
    				move_state.debounce_count_ymin++;
    			}
    			else
    			{
    				move_state.debounce_count_ymin = 0;
    			}
    
    			#endif
    
    			#if defined Y_MAX_PIN
    
    			if(y_max() == dda->endstop_stop_cond)
    			{
    				move_state.debounce_count_ymax++;
    			}
    			else
    			{
    				move_state.debounce_count_ymax = 0;
    			}
    
    			#endif
    
    			endstop_trigger = move_state.debounce_count_ymin >= ENDSTOP_STEPS ||
    				move_state.debounce_count_ymax >= ENDSTOP_STEPS;
    		}
    
    		#endif
    
    		#if defined Z_MIN_PIN || defined Z_MAX_PIN
    
    		if(dda->endstop_check & 0x4)
    		{
    			#if defined Z_MIN_PIN
    
    			if(z_min() == dda->endstop_stop_cond)
    			{
    				move_state.debounce_count_zmin++;
    			}
    			else
    			{
    				move_state.debounce_count_zmin = 0;
    			}
    
    			#endif
    
    			#if defined Z_MAX_PIN
    
    			if(z_max() == dda->endstop_stop_cond)
    			{
    				move_state.debounce_count_zmax++;
    			}
    			else
    			{
    				move_state.debounce_count_zmax = 0;
    			}
    
    			#endif
    
    			endstop_trigger = move_state.debounce_count_zmin >= ENDSTOP_STEPS ||
    				move_state.debounce_count_zmax >= ENDSTOP_STEPS;
    		}
    
    		#endif
    
    		//If an endstop is definitely triggered, stop the movement.
    		if(endstop_trigger)
    		{
    			#ifdef ACCELERATION_RAMPING
    
    			//For always smooth operations, don't halt apruptly,
    			//but start deceleration here.
    			ATOMIC_START
    
    			move_state.endstop_stop = 1;
    
    			if(move_state.step_no < dda->rampup_steps)  //still accelerating
    			{
    				dda->total_steps = move_state.step_no * 2;
    			}
    			else
    			{
    				//A "-=" would overflow earlier.
    				dda->total_steps = dda->total_steps - dda->rampdown_steps + move_state.step_no;
    			}
    
    			dda->rampdown_steps = move_state.step_no;
    
    			ATOMIC_END
    
    
    			// Not atomic, because not used in dda_step().
    			dda->rampup_steps = 0; // in case we're still accelerating
    
    			#else
    
    			dda->live = 0;
    
    			#endif
    
    			endstops_off();
    		}
    	}
    
    

    Source: Teacup firmware - dda.c
  • kwinnkwinn Posts: 8,697
    edited 2015-02-06 07:32
    @ idbruce

    An Estop should really shut off power to all the motors, heaters, etc. directly rather depend on software to do it. Not a big issue for a small 3D printer but a concern if someone was to adapt it to a larger more hazardous machine like a router or mill.

    Using a single pin for multiple limit switches is relatively simple to do. The program knows which axis are in motion and the direction of travel so stopping all motion and then reversing direction on each axis in turn will determine which limit switch was active.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-06 09:54
    kwinn

    Thanks for the input.
    An Estop should really shut off power to all the motors, heaters, etc. directly rather depend on software to do it. Not a big issue for a small 3D printer but a concern if someone was to adapt it to a larger more hazardous machine like a router or mill.

    I agree, in fact, several months ago, when we were all discussing limit switches and E-STOPs, I believe someone spit out a reference to a federal regulation, which stipulated the requirements for E-STOPS. I was actually using E-STOP very loosely, and it is just a means of stopping a machine, which uses the controller board linked to in Post #1, more specifically a tact switch :)
    Using a single pin for multiple limit switches is relatively simple to do. The program knows which axis are in motion and the direction of travel so stopping all motion and then reversing direction on each axis in turn will determine which limit switch was active.

    Once again, back when we were discussing this issue, either you or some else brought that point or a similar point up, however I had completely forgot about most of that discussion. Thanks for reminding me.

    In all honesty, I doubt that I will currently try to implement that scenario into the code at this point. However, I also doubt that it would be too difficult, when in most likelihood, it would probably be pretty easy, but currently I have one BIG fish to fry :)
  • idbruceidbruce Posts: 6,197
    edited 2015-02-06 10:47
    After a lot more drudgery..............

    DDA.spin is now in a lot better shape for actual porting, as with the last upload of this file, there is still some C lingering about as clues for future work that must be done. As you go through this file, you will see several comments that start with "Per Bruce:". These specific areas represent various problems that I am having with a speedy port or items that may present a problem.

    Additionally, as you go through the file, you will see a very large amount of variables being used, with some very lengthy names, and yes I know that some of these will need to be shortened to enable compiling. As I work on this file, I just want to make certain that each intended unique variable remains unique. Another issue pertaining to the number of variables, is that many of the required structures, already had many variables, so I had to follow the lead of the firmware.

    Anyhow, here is the current state of porting dda.c to SPIN.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 02:51
    And so the journey begins.... Traveling from one Teacup file to another.

    Since my last posting, I have been spending some time eliminating some or most of the remaining C within DDA.spin, and I must say that it is now actually beginning to look like a SPIN file. Additionally, I think I am fairly close to getting DDA.spin to compile, however my current compiling efforts, now require the porting and understanding of dda_queue.c, before DDA.spin can be completed, but dda_queue.c won't even be a fraction of the battle that I had with DDA.c.

    Besides the required porting of dda_queue.c, there has also been a lot of references to pinio.c, but in those instances, it was pretty much a case of just simply assigning values or directions to pins. Whereas Teacup pinio.c had actual functions for making or altering these settings, I simply made the changes in DDA.spin.

    After porting dda_queue.c and getting DDA.spin to compile, I believe I will concentrate on finishing the Z axis of the machine, and perhaps start working on the heated build platform. At this point, I have spent way too many hours looking at C and SPIN. :)

    EDIT: Just in case anyone is interested, I will attach a copy of DDA.spin
  • idbruceidbruce Posts: 6,197
    edited 2015-02-08 22:06
    Yesterday I decided to take a break from porting Teacup to SPIN and examine the possibilites of porting existing C code to the Propeller-GCC. While I found it all to be very interesting, playing with SimpleIDE and GCC for the first time, it certainly was no cake walk. My difficulties had nothing to do with SimpleIDE, it was more a matter of the Teacup files. In fact, I thought SimpleIDE was very nice, however the Teacup files were not so nice. There was error upon error, and warning upon warning. Just when I thought I had weeded out all the errors, a whole batch of errors would arise, and this did even begin to include all the warnings. By the time I got finished toying around with it, the Teacup source code was torn to shreds, so I finally gave up on that plan, and decided to return to a SPIN port. Realizing that the SPIN port is no cake walk either, I decided to change my strategy a bit and decided to rewrite a lot of what has already been done. Or should I say edit what has already been done.

    Before diving in, I decided to map the function calls of what I consider to be the most important files of Teacup, and apply valuable comments to these function calls, so that I may obtain a much better understanding of the firmware then I already have, and I must say that I think it was well worth the effort,, because I have now physically and mentally traced the process of execution, meanwhile documenting it for future reference.

    Starting tomorrow, I will begin to further disect the firmware into more critical components and rip out all of the arduino references, that only complicate a clear vision of what needs to be done to make it fit well with the Propeller architecture. If there is anybody out there that has been reviewing the Teacup files and have become a little overwhelmed by all the files and source code, I now submit to you an archive that contains five text files, which map the critical functions of the Teacup firmware.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2015-02-09 06:26
    As it pertains to my last post..... I have changed my mind. Instead of editing what has already been written in SPIN, I have decided to start fresh, with a clean slate, and start all over again. Only this time, I will be doing things quite differently. Instead of hopping back and forth between various files, doing a bunch of find and replace alls, I will be creating one GIANT C file, which contains all of the critical functions that I intend to port, and then I will do all of my finds and replace alls. Most likely, all of these functions will end up in one GIANT SPIN file anyhow, so that all of the variables are readily accessible within one object. The code will be a real pain to edit and find stuff, but I think this will be my easiest route, with the least amount of headaches.

    Additionally, I have also decided to support a few more options then I originally intended, mostly because I now have a much better understanding of implementing these options, and the options would be nice to have.

    Time for Round #3 - DING DING - Let the bell ring!
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-02-09 07:07
    Bruce, I looked at the Teacup C code over the weekend, and there's a simulator mode that you could enable. It might be worth pursuing that if it eliminates most of the Arduino stuff. I would suggest not creating one giant file. I think that would make the code harder to work with.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-09 08:36
    Dave
    Bruce, I looked at the Teacup C code over the weekend, and there's a simulator mode that you could enable. It might be worth pursuing that if it eliminates most of the Arduino stuff.

    As you may have guessed, the more time I spend on reviewing the source code, the better I become acquainted with it. While I believe that I now know the machine movement code fairly well, there are still several sections of the code that I have not spent any time reviewing or have reviewed them very little. The simulator would be one aspect of the code that I really know nothing about. From my understanding though, the simulator basically shows you how the movements are executed. As it pertains to available options, I do believe at this point, in addition to the original items I planned on supporting, I think I will now also be supporting DEBUG, LOOKAHEAD, ACCELERATION_REPRAP, and ACCELERATION_TEMPORAL.
    I would suggest not creating one giant file. I think that would make the code harder to work with.

    Well that would all depend on how you look at it. For turning the code into SPIN, I think it would be much easier to edit one large file, as compared to several small files. However for program managability, I would have to agree with you 100%, but then again, a person would have to be well versed in SPIN to enable all them objects to communicate with each other and share data. And I just don't believew that I have the SPIN skills for that. I am sure I could do it in C, but not in SPIN. And then again, perhaps I would be better offf pursing a C port than a SPIN port.

    In reality, it would probably be much easier working out all of the C problems, as oppesed to converting it to SPIN. One of the key turn-offs for going with C was the use of memcpy. Something that should have been simple, resulted in many, many warnings. For example:
    dda.c:85:2: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
    dda.c:85:2: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
    

    I couldn't find any information about which library memcpy was located in, therefore I could not see the declaration or what was expected.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-09 09:37
    Now We Are Talking Possibilities!

    Source:
    #include "config.h"
    #include "clock.h"
    #include "config_wrapper.h"
    #include "dda.h"
    #include "dda_maths.h"
    #include "dda_queue.h"
    #include "delay.h"
    #include "gcode_parse.h"
    #include "gcode_process.h"
    #include "memory_barrier.h"
    #include "pinio.h"
    #include "serial.h"
    #include "sermsg.h"
    #include "sersendf.h"
    #include "temp.h"
    //#include "ThermistorTable.double.h"
    //#include "ThermistorTable.single.h"
    #include "timer.h"
    #include <math.h>
    #include	<stdint.h>
    #include <stdlib.h>
    #include	<string.h>
    
    int main(void)
    {
      return 0;
    }
    

    Result:
    attachment.php?attachmentid=113135&d=1423503447
    631 x 219 - 33K
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-02-09 09:40
    The prototype for memcpy is in string.h. I go to http://www.cplusplus.com when I need to look up something in C.

    EDIT: I see you figured it out while I was typing my response.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-09 09:45
    Dave
    I see you figured it out while I was typing my response.

    Yea.... Temporarily :) but it opens up possibities. However the SIMULATOR option is definitely out of the question, because it relies upon the AVR libraries, and I am certainly not going to poke my nose around in there.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-09 09:56
    Hey Dave

    Let me ask you a question that I am unsure of, or actually a couple.

    1. Since I included all of those files, that should be equal in program size to a running Teacup, shouldn't it?????? I would think so.

    2. And if the build succeeded, that would mean it should fit within Propeller memory, shouldn't it???????

    EDIT: I said that wrong.... It should be as follows:

    Since the build succeeded, then Teacup should fit into EEPROM, or it should aready be there correct????

    As for running, is there anyway to determine how much RAM I need for the program to run?????

    EDIT: LOL..... I forgot to add the C files..... Now I have several errors
  • idbruceidbruce Posts: 6,197
    edited 2015-02-09 11:45
    Arduino and AVR are wrapped up so tightly in that code, that is makes it very difficult to get anywhere near a successful compile with the C code added :)
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-02-09 12:09
    In SimpleIDE the code size and total program size should be displayed at the lower left of the window if the build is successful.

    I recall there were a lot of Arduino/AVR references in the code when I looked at it last year. For now you should be able to create stub routines to get it to compile and link. Eventually you will need to provide Prop replacement code for those routines.
Sign In or Register to comment.