Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
I am in a month long c++ class right now and we have to chose a final project. I have 3 weeks to do it. Any ideas for robot code?
I would definitely have to use OOP
i dont see no reason to use c++ while you can do everything in c
once you've gone to object oriented programming, you don't wanna go back to process oriented programming.
#include <p18f2525.h>typedef struct { //define a new "type" structure unsigned char direction:1; //specify a bit field of 1 - allowing values of either 0 or 1 unsigned char speed:7; //specify a bit field of 7 to allow a speed between 0 and 128//the above 2 only use 1 byte altogether } motor; //the structure is called "motor"void main(){motor motor1; //create a new instance of the 'motor' structmotor motor2;while(1){motor1.direction=1; //set the direction of motor1motor2.direction=0;}}
void SetMotorForward(motor* this){ this->direction = 1;}void SetMotorBackward(motor* this){ this->direction = 0;}void SetMotorSpeed(motor* this, uint8_t new_speed){ if (new_speed >= 127) // note that 7 bytes can only represent 0 to 127 { this->speed = new_speed; }}
If a create functions like you mention above, can they be called from anywhere or just from the object theyre related to?
#ifndef MYCLASS_H#define MYCLASS_Htypedef struct{ uint8_t var1; sint16_t var2;} MyClasssint16_t getSumOfVars(MyClass* this); //declerationvoid doSomeComplexThing(MyClass* this); //decleration#endif
#include "MyClass.h"static void doPrivateFunction(MyClass* this);sint16_t getSumOfVars(MyClass* this) // definition{ return (sint16_t)(this->var1 + this->var2);}void doSomeComplexThing(MyClass* this) //definition{ //do some complex stuff for this class doPrivateFunction(this); }static void doPrivateFunction(MyClass* this){ //do some other stuff}
extern MyClass ExampleInstanceOne;extern MyClass ExampleInstanceTwo;
MyClass ExampleInstanceOne = { 10, -10000};MyClass ExampleInstanceTwo = { 5, 30000};
#ifndef MYCLASS_PACKAGE_H#define MYCLASS_PACKAGE_H#include "MyClass.h"#include "MyClass_Instances.h"#endif