Notifications
Clear all

Firmware development help  

  RSS
Night Skies
(@night-skies)
Active Member
Firmware development help

Hi,

Anybody here familiar with the firmware source? I've dived into it myself and there's a few things that I could use pointers on. Having somebody else point out the design is oftentimes quicker than figuring it out yourself.

* How are commands enqueued? It looks like it uses get_command and process_commands from the loop() function in order to operate primarily. Am I right? It looks like process_commands is handling G-codes directly? But my question is what is on the other end of the serial port that is sending commands? Is this an internal serial port? Also where is the UI interaction happening?

If I figure out where commands are enqueued, I can find out where it comes from. And then I need to have custom command parsing to do the following:
* Control an external power controller using some sort of pin on the RAMBo
* Control an on/off power controller using another pin
* Control a couple other things like a gas valve using a pin

This is for my metal printing modification, which has proceeded past the "printing by hand" stage and is onto printing by machine.

Thanks

Posted : 24/01/2018 1:51 pm
Night Skies
(@night-skies)
Active Member
Topic starter answered:
Re: Firmware development help

Haven't heard from anyone, and I tried contacting a developer but to no avail. Can anybody help?

Posted : 31/01/2018 1:54 pm
Zinga
(@zinga)
Trusted Member
Re: Firmware development help

If you're wanting to make custom g-code commands that will be embedded in the .gcode print file or over a USB serial connection, I don't think you have to dig very far into how the command code works. It looks like all you need to do is add your custom commands into Marlin_main.cpp. You use code_seen(<char>) which returns true if the current command contains that character and sets the pointer that code_value() uses to return the value. (Ex: Command="G80" then code_seen('G') returns true and code_value() returns (float)80. There's different code_value()'s you can use for other types.

// Return True if a character was found
static inline bool code_seen(char code) { return (strchr_pointer = strchr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
static inline bool code_seen(const char *code) { return (strchr_pointer = strstr(CMDBUFFER_CURRENT_STRING, code)) != NULL; }
static inline float code_value() { return strtod(strchr_pointer+1, NULL);}
static inline long code_value_long() { return strtol(strchr_pointer+1, NULL, 10); }
static inline int16_t code_value_short() { return int16_t(strtol(strchr_pointer+1, NULL, 10)); };
static inline uint8_t code_value_uint8() { return uint8_t(strtol(strchr_pointer+1, NULL, 10)); };

static inline float code_value_float() {
char* e = strchr(strchr_pointer, 'E');
if (!e) return strtod(strchr_pointer + 1, NULL);
*e = 0;
float ret = strtod(strchr_pointer + 1, NULL);
*e = 'E';
return ret;
}

In Marlin_main.cpp you'll see big sections, including code_seen('G') and code_seen('M') followed by a switch statement on code_value(), and then each case is for the possible gcode commands. Easiest thing would probably be to add your commands inside the M section using a value that isn't being used.

case 224: // M950S<on/off> - turn on power controller, S0 or S1
{
if(code_seen('S'))
{
int pwrState = code_value_uint8();
set_pwrCntr(pwrState); // Function to change the power state of the controller
}
}
break;

You may also want to take a look at http://reprap.org/wiki/G-code which has some information on best practices.

Posted : 06/02/2018 9:20 am
Night Skies
(@night-skies)
Active Member
Topic starter answered:
Re: Firmware development help

Thanks. I actually was able to figure that part out too.

I think my main challenges right now are figuring out the power controller. It's a stepper motor that I believe I can control with extruder motor controller 1 or something. Trouble is I have a stepper with 6 wires and not 4. I've read a little bit into the types of steppers and perhaps I just have a kind that cannot be used directly with it.

Next step would be figuring out how to use said stepper motor from code.

Does anybody have any idea how to detect when a stepper motor is stuck? Or perhaps I just turn it until I know it'll be stuck? (like turn it 100% turn to the left, let it jam out at the end, and then stop and I'll know I'm at position 0).

Posted : 20/02/2018 8:18 pm
Share: