ROBOTC.net forums
http://www.robotc.net/forums/

Downloading source to robot corrupts firmware?
http://www.robotc.net/forums/viewtopic.php?f=11&t=12327
Page 1 of 1

Author:  tyridge77 [ Thu Oct 01, 2015 10:49 am ]
Post subject:  Downloading source to robot corrupts firmware?

Hello all, I'm new to RobotC and robotics in general, but I've done a little bit of programming in the past for fun.
Anyways, I don't like the restrictions for ordinary arrays, so I tried making my own linked list data structure.
The problem is, even when I only make one node, it corrupts the firmware apparently because it makes the program crash and I can only seem to fix it by
re-downloading the firmware in the Robot program. Why is this happening? Is it my code? (I'm not a very good programmer lol)

Anyways, here's the code so far that causes problems.

Code:
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl3,  Output,         sensorSONAR_cm)
#pragma config(Sensor, dgtl12, Rot,            sensorNone)
#pragma config(Sensor, I2C_1,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port2,           Neck,          tmotorVex393_MC29, openLoop, encoderPort, I2C_1)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//




// Linked List, contains a series of references to nodes, acts as an array without the size restrictions.

struct node
{
 int value;
 node*nextnode;
}

struct node* lastnode;


void appendtolist(int x)
{
 struct node* newnode;
 newnode->value=x;
 lastnode->nextnode=newnode;
}


float Revolutions()
{
 return SensorValue[I2C_1]/(float)650;
}

task main()
{

 struct node* root;
 lastnode=root;

 appendtolist(1);


 while(1+1==2)
 {
  int dist = SensorValue(Output);
  writeDebugStream("\nDist: %f, Revolutions: %f",dist,Revolutions());
  motor[Neck]=(dist<5?0:20);


  //start at 0,
  //-1 for left until full revolution
  // +1 for right until full revolution


 }
 motor[Neck]=0;
}


I know it's the linked list, because when I comment out appendtolist and everything the program works fine.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/